-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.tsx
More file actions
281 lines (263 loc) · 8.2 KB
/
index.tsx
File metadata and controls
281 lines (263 loc) · 8.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import React from "react";
import { BarChart, ColumnChart, LineChart } from "react-chartkick";
import "chart.js";
import { colors } from "tailwindcss/defaultTheme";
import Layout from "../components/layout";
import SEO from "../components/seo";
import lastUpdateAt from "../../data/last_updated_at.json";
import countedStats from "../../data/counted_stats.json";
import returningMembers from "../../data/returning_members.json";
import studentCoachConversion from "../../data/student_to_coach_conversion.json";
import attendedPerYear from "../../data/attended_per_year.json";
import newSignUpsPerYear from "../../data/new_signups.json";
import workshopsPerYear from "../../data/workshops_per_year.json";
import ratingsPerYear from "../../data/ratings_per_year.json";
import averageRatingsPerMonth from "../../data/average_rating_per_month.json";
type Data = {
coach_count: number;
student_count: number;
chapter_count: number;
workshop_count: number;
monthlies_count: number;
events_count: number;
percentage_returning: number;
student_to_coach_conversion: number;
busiest_month: number;
average_rating: number;
};
const data: Data = {
...countedStats,
...returningMembers,
...studentCoachConversion,
};
const attendedPerYearChart = [
{
name: "Students",
data: attendedPerYear.map(({ students, year }) => [
year.toString(),
students,
]),
},
{
name: "Coaches",
data: attendedPerYear.map(({ coaches, year }) => [
year.toString(),
coaches,
]),
},
];
const newSignUpsPerYearChart = [
{
name: "Students",
data: newSignUpsPerYear.map(({ studentcount, year }) => [
year.toString(),
studentcount,
]),
},
{
name: "Coaches",
data: newSignUpsPerYear.map(({ coachcount, year }) => [
year.toString(),
coachcount,
]),
},
];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const ratingSet = (_data: any, rating: number) => ({
name: rating,
data: ratingsPerYear
.filter((c) => c.rating === rating)
.map(({ year, count }) => [year, count]),
});
const ratingsPerYearChart = [
ratingSet(ratingsPerYear, 1),
ratingSet(ratingsPerYear, 2),
ratingSet(ratingsPerYear, 3),
ratingSet(ratingsPerYear, 4),
ratingSet(ratingsPerYear, 5),
];
const averageRatingChart = [
{
name: "Average rating",
data: averageRatingsPerMonth.map(({ month, year, avg }) => [
new Date(year, month - 1),
avg,
]),
},
];
const workshopsPerYearChart = [
{
name: "Workshops per year",
data: workshopsPerYear.map(({ count, year }) => [year.toString(), count]),
},
];
// const attendedPerYearTable: string[][] = attendedPerYear
// .slice(0)
// .map((item, i) => {
// const previousYear = attendedPerYear[i - 1] || {};
// const currentYearAttending = item.coaches + item.students;
// const previousYearAttending = previousYear.coaches + previousYear.students;
// const percentageChange =
// (currentYearAttending / previousYearAttending) * 100 - 100;
// return [
// item.year,
// item.coaches + item.students,
// (percentageChange || 0).toFixed(2),
// ].map((item) => item.toString());
// });
const dataDisplay = [
{ property: "coach_count", title: "Coaches" },
{ property: "student_count", title: "Students" },
{ property: "chapter_count", title: "Chapters" },
{ property: "workshop_count", title: "Workshops" },
{ property: "monthlies_count", title: "Monthlies" },
{ property: "events_count", title: "Other Events" },
{ property: "percentage_returning", title: "Returning Members %" },
{ property: "student_to_coach_conversion", title: "Students > Coaches %" },
];
const monthMap = new Map([
[1, "January ❄️"],
[2, "February 💝"],
[3, "March 🌼"],
[4, "April 🐣"],
[5, "May 🌸"],
[6, "June 🌞"],
[7, "July 🍦"],
[8, "Aug 🦋"],
[9, "Sept 🍂"],
[10, "October 🎃"],
[11, "Nov 🍂"],
[12, "Dec 🎄"],
]);
function IndexPage(): JSX.Element {
return (
<Layout>
<SEO
description="codebar stats"
keywords={[
`gatsby`,
`tailwind`,
`react`,
`tailwindcss`,
`codebar`,
`stats`,
]}
title="Home"
/>
<section>
<h1>codebar Overview</h1>
<p className="text-sm font-semibold text-gray-800">
Last updated:{" "}
{new Date(lastUpdateAt.last_updated_at).toLocaleDateString()}
</p>
<dl className="grid sm:grid-cols-3 gap-6">
{dataDisplay.map((item) => (
<div key={item.property}>
<dd className="text-5xl font-extrabold leading-none text-blue-500">
{data[item.property as keyof Data].toLocaleString()}
</dd>
<dt className="mt-2 text-lg font-medium text-gray-700 leading-6">
{item.title}
</dt>
</div>
))}
</dl>
<h1>Workshops</h1>
<div className="space-y-12">
<div className="flex">
<div className="flex-grow bg-gray-200 px-4 py-2 m-2">
<ColumnChart
data={workshopsPerYearChart}
colors={[colors.blue["600"]]}
/>
</div>
<dl className="grid sm:grid-cols-2 gap-6 m-2 text-center items-center">
<div>
<dd className="text-3xl font-extrabold leading-none text-blue-500">
{countedStats.workshop_count}
</dd>
<dt className="mt-2 font-medium text-gray-700 leading-6">
All workshops
</dt>
</div>
<div>
<dd className="text-3xl font-extrabold leading-none text-blue-500">
{monthMap.get(countedStats.busiest_month)}
</dd>
<dt className="mt-2 font-medium text-gray-700 leading-6">
Busiest month
</dt>
</div>
<div>
<dd className="text-3xl font-extrabold leading-none text-blue-500">
{monthMap.get(countedStats.slowest_month)}
</dd>
<dt className="mt-2 font-medium text-gray-700 leading-6">
Slowest month
</dt>
</div>
</dl>
</div>
<h3>Workshop and Event attendance per year</h3>
<BarChart
data={attendedPerYearChart}
stacked
colors={[colors.blue["500"], colors.pink["600"]]}
/>
{/* <h3>Workshop growth</h3>
<Table
headers={["Year", "Attendances", "Growth %"]}
rows={attendedPerYearTable}
/> */}
</div>
<h1>Members</h1>
<h3>New members per year</h3>
<div className="space-y-12">
<ColumnChart
data={newSignUpsPerYearChart}
stacked
colors={[colors.blue["500"], colors.pink["600"]]}
/>
</div>
<h1>Feedback</h1>
<div className="space-y-12 mb-12">
<h3>Ratings per year</h3>
<BarChart
data={ratingsPerYearChart}
stacked
colors={[
colors.red["600"],
colors.orange["600"],
colors.yellow["600"],
colors.blue["600"],
colors.pink["600"],
]}
/>
</div>
<div className="space-y-12">
<h3>Average rating</h3>
<div className="flex">
<div className="flex-grow bg-gray-200 px-4 py-2 m-2">
<LineChart
data={averageRatingChart}
colors={[colors.pink["600"]]}
max={5}
/>
</div>
<dl className="grid sm:grid-cols-1 gap-6 m-2 text-center items-center">
<div>
<dd className="text-3xl font-extrabold leading-none text-blue-500">
{countedStats.average_rating.toFixed(1)}
</dd>
<dt className="mt-2 font-medium text-gray-700 leading-6">
Average rating
</dt>
</div>
</dl>
</div>
</div>
</section>
</Layout>
);
}
export default IndexPage;