Xianbao QIAN commited on
Commit
0c2c8f3
·
1 Parent(s): 9e2f4be

/trend: plot worksforboth

Browse files
Files changed (2) hide show
  1. src/pages/trend/index.tsx +9 -1
  2. src/utils/modelData.ts +31 -14
src/pages/trend/index.tsx CHANGED
@@ -75,6 +75,14 @@ const TrendPage: React.FC<TrendProps> = ({ monthlyData = [], totalData = [], det
75
  );
76
  };
77
 
 
 
 
 
 
 
 
 
78
  // Group data by provider
79
  const providerData = Object.fromEntries(
80
  Object.keys(PROVIDERS_MAP).map(provider => {
@@ -221,7 +229,7 @@ const TrendPage: React.FC<TrendProps> = ({ monthlyData = [], totalData = [], det
221
  {/* Total Line */}
222
  {showTotal && (
223
  <Line
224
- data={totalData}
225
  type="monotone"
226
  dataKey="count"
227
  stroke={COLORS['Total']}
 
75
  );
76
  };
77
 
78
+ // Filter total data based on content type
79
+ const filteredTotalData = totalData.filter(d => {
80
+ const matchesContentType = contentType === 'all' ||
81
+ (contentType === 'datasets' && d.isDataset) ||
82
+ (contentType === 'models' && !d.isDataset);
83
+ return matchesContentType;
84
+ });
85
+
86
  // Group data by provider
87
  const providerData = Object.fromEntries(
88
  Object.keys(PROVIDERS_MAP).map(provider => {
 
229
  {/* Total Line */}
230
  {showTotal && (
231
  <Line
232
+ data={filteredTotalData}
233
  type="monotone"
234
  dataKey="count"
235
  stroke={COLORS['Total']}
src/utils/modelData.ts CHANGED
@@ -116,19 +116,23 @@ export const aggregateCalendarData = (calendarData: CalendarData): Activity[] =>
116
  };
117
 
118
  export const generateMonthlyData = (modelData: ModelData[]): MonthlyActivity[] => {
119
- const monthlyData: Record<string, Record<string, MonthlyActivity>> = {};
120
 
121
  modelData.forEach(model => {
122
  const date = new Date(model.createdAt);
123
  const monthKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`;
124
  const provider = model.provider || 'unknown';
 
125
 
126
  if (!monthlyData[monthKey]) {
127
  monthlyData[monthKey] = {};
128
  }
129
-
130
  if (!monthlyData[monthKey][provider]) {
131
- monthlyData[monthKey][provider] = {
 
 
 
 
132
  date: monthKey,
133
  count: 0,
134
  provider,
@@ -137,11 +141,16 @@ export const generateMonthlyData = (modelData: ModelData[]): MonthlyActivity[] =
137
  };
138
  }
139
 
140
- monthlyData[monthKey][provider].count++;
141
  });
142
 
 
143
  return Object.values(monthlyData)
144
- .flatMap(providerData => Object.values(providerData))
 
 
 
 
145
  .sort((a, b) => a.date.localeCompare(b.date));
146
  };
147
 
@@ -271,17 +280,25 @@ export function processDetailedModelData(models: ModelData[]): DetailedModelData
271
 
272
  // Helper function to get total monthly data across all providers
273
  export const getTotalMonthlyData = (monthlyData: MonthlyActivity[]): MonthlyActivity[] => {
274
- const totalByMonth: Record<string, number> = {};
275
 
276
- monthlyData.forEach(({ date, count }) => {
277
- totalByMonth[date] = (totalByMonth[date] || 0) + count;
 
 
 
 
 
 
 
 
 
 
 
 
278
  });
279
 
280
- return Object.entries(totalByMonth)
281
- .map(([date, count]) => ({
282
- date,
283
- count,
284
- provider: 'Total'
285
- }))
286
  .sort((a, b) => a.date.localeCompare(b.date));
287
  };
 
116
  };
117
 
118
  export const generateMonthlyData = (modelData: ModelData[]): MonthlyActivity[] => {
119
+ const monthlyData: Record<string, Record<string, Record<string, MonthlyActivity>>> = {};
120
 
121
  modelData.forEach(model => {
122
  const date = new Date(model.createdAt);
123
  const monthKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`;
124
  const provider = model.provider || 'unknown';
125
+ const type = model.isDataset ? 'dataset' : 'model';
126
 
127
  if (!monthlyData[monthKey]) {
128
  monthlyData[monthKey] = {};
129
  }
 
130
  if (!monthlyData[monthKey][provider]) {
131
+ monthlyData[monthKey][provider] = {};
132
+ }
133
+
134
+ if (!monthlyData[monthKey][provider][type]) {
135
+ monthlyData[monthKey][provider][type] = {
136
  date: monthKey,
137
  count: 0,
138
  provider,
 
141
  };
142
  }
143
 
144
+ monthlyData[monthKey][provider][type].count++;
145
  });
146
 
147
+ // Flatten the nested structure
148
  return Object.values(monthlyData)
149
+ .flatMap(providerData =>
150
+ Object.values(providerData).flatMap(typeData =>
151
+ Object.values(typeData)
152
+ )
153
+ )
154
  .sort((a, b) => a.date.localeCompare(b.date));
155
  };
156
 
 
280
 
281
  // Helper function to get total monthly data across all providers
282
  export const getTotalMonthlyData = (monthlyData: MonthlyActivity[]): MonthlyActivity[] => {
283
+ const totalByMonth: Record<string, Record<string, MonthlyActivity>> = {};
284
 
285
+ monthlyData.forEach(({ date, count, isDataset }) => {
286
+ const type = isDataset ? 'dataset' : 'model';
287
+ if (!totalByMonth[date]) {
288
+ totalByMonth[date] = {};
289
+ }
290
+ if (!totalByMonth[date][type]) {
291
+ totalByMonth[date][type] = {
292
+ date,
293
+ count: 0,
294
+ provider: 'Total',
295
+ isDataset: isDataset
296
+ };
297
+ }
298
+ totalByMonth[date][type].count += count;
299
  });
300
 
301
+ return Object.values(totalByMonth)
302
+ .flatMap(typeData => Object.values(typeData))
 
 
 
 
303
  .sort((a, b) => a.date.localeCompare(b.date));
304
  };