Xianbao QIAN commited on
Commit
2ea1dfc
1 Parent(s): 913402a

show derived model count

Browse files
Files changed (4) hide show
  1. .gitignore +3 -0
  2. bun.lockb +0 -0
  3. package.json +3 -2
  4. src/app/page.tsx +71 -36
.gitignore CHANGED
@@ -34,3 +34,6 @@ yarn-error.log*
34
  # typescript
35
  *.tsbuildinfo
36
  next-env.d.ts
 
 
 
 
34
  # typescript
35
  *.tsbuildinfo
36
  next-env.d.ts
37
+
38
+ # DuckDB temp files.
39
+ .tmp
bun.lockb CHANGED
Binary files a/bun.lockb and b/bun.lockb differ
 
package.json CHANGED
@@ -9,9 +9,10 @@
9
  "lint": "next lint"
10
  },
11
  "dependencies": {
 
 
12
  "react": "^18",
13
- "react-dom": "^18",
14
- "next": "14.2.15"
15
  },
16
  "devDependencies": {
17
  "typescript": "^5",
 
9
  "lint": "next lint"
10
  },
11
  "dependencies": {
12
+ "next": "14.2.15",
13
+ "parquetjs-lite": "^0.8.7",
14
  "react": "^18",
15
+ "react-dom": "^18"
 
16
  },
17
  "devDependencies": {
18
  "typescript": "^5",
src/app/page.tsx CHANGED
@@ -1,45 +1,80 @@
1
  import fs from 'fs';
2
  import path from 'path';
 
3
 
4
- type DataItem = {
5
- title: string;
6
- description: string;
7
- data: any[];
8
- };
9
-
10
- type Data = {
11
- title: string;
12
- description: string;
13
- data: DataItem[];
14
  };
15
 
16
  export default async function Home() {
17
- // Read the JSON file
18
- const jsonDirectory = path.join(process.cwd(), 'content');
19
- const fileContents = await fs.readFileSync(jsonDirectory + '/data.json', 'utf8');
20
- const data: Data = JSON.parse(fileContents);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- return (
23
- <main className="container mx-auto py-8 text-gray-900 dark:text-white">
24
- <h1 className="text-4xl font-bold mb-4">{data.title}</h1>
25
- <p className="text-xl mb-8">{data.description}</p>
26
 
27
- <table className="table-auto border-collapse w-full">
28
- <thead>
29
- <tr>
30
- <th className="px-4 py-2 bg-gray-100 dark:bg-gray-800 text-left">Title</th>
31
- <th className="px-4 py-2 bg-gray-100 dark:bg-gray-800 text-left">Description</th>
32
- </tr>
33
- </thead>
34
- <tbody>
35
- {data.data.map((item: DataItem, index: number) => (
36
- <tr key={index} className="border-t border-gray-200 dark:border-gray-700">
37
- <td className="px-4 py-2">{item.title}</td>
38
- <td className="px-4 py-2">{item.description}</td>
39
- </tr>
40
- ))}
41
- </tbody>
42
- </table>
43
- </main>
44
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  }
 
1
  import fs from 'fs';
2
  import path from 'path';
3
+ import { ParquetReader } from 'parquetjs-lite';
4
 
5
+ type ModelData = {
6
+ ancestor: string;
7
+ direct_children: string[] | null;
8
+ all_children: string[];
9
+ all_children_count: number;
10
+ direct_children_count: number | null;
 
 
 
 
11
  };
12
 
13
  export default async function Home() {
14
+ try {
15
+ // Read the Parquet file using parquetjs-lite
16
+ const parquetFilePath = path.join(process.cwd(), 'tables', 'ancestor_children.parquet');
17
+ const reader = await ParquetReader.openFile(parquetFilePath);
18
+ const cursor = reader.getCursor();
19
+
20
+ // Read all rows and convert to a JavaScript array
21
+ const data: ModelData[] = [];
22
+ let row = null;
23
+ while (row = await cursor.next()) {
24
+ data.push({
25
+ ancestor: row.ancestor,
26
+ direct_children: row.direct_children,
27
+ all_children: row.all_children,
28
+ all_children_count: row.all_children_count,
29
+ direct_children_count: row.direct_children_count,
30
+ });
31
+ // console.log(row.all_children.list.length)
32
+ }
33
+ await reader.close();
34
+
35
+ // console.log('Data:', data);
36
+
37
+ // Get the top 10 models with the most all_children
38
+ const top10Models = data
39
+ .sort((a, b) => b.all_children.length - a.all_children.length)
40
+ .slice(0, 10);
41
 
42
+ // console.log('Top 10 Models:', top10Models);
 
 
 
43
 
44
+ return (
45
+ <main className="container mx-auto py-8 text-gray-900 dark:text-white">
46
+ <h1 className="text-4xl font-bold mb-4">Top 10 Models with the Most All Children</h1>
47
+ {top10Models.length > 0 ? (
48
+ <table className="table-auto border-collapse w-full">
49
+ <thead>
50
+ <tr>
51
+ <th className="px-4 py-2 bg-gray-100 dark:bg-gray-800 text-left">Model</th>
52
+ <th className="px-4 py-2 bg-gray-100 dark:bg-gray-800 text-right">Direct Children</th>
53
+ <th className="px-4 py-2 bg-gray-100 dark:bg-gray-800 text-right">All Children</th>
54
+ </tr>
55
+ </thead>
56
+ <tbody>
57
+ {top10Models.map((model, index) => (
58
+ <tr key={index} className="border-t border-gray-200 dark:border-gray-700">
59
+ <td className="px-4 py-2">{model.ancestor}</td>
60
+ <td className="px-4 py-2 text-right">{model.direct_children_count ?? 0}</td>
61
+ <td className="px-4 py-2 text-right">{model.all_children_count}</td>
62
+ </tr>
63
+ ))}
64
+ </tbody>
65
+ </table>
66
+ ) : (
67
+ <p>No data found.</p>
68
+ )}
69
+ </main>
70
+ );
71
+ } catch (error) {
72
+ console.error('Error:', error);
73
+ return (
74
+ <main className="container mx-auto py-8 text-gray-900 dark:text-white">
75
+ <h1 className="text-4xl font-bold mb-4">Error</h1>
76
+ <p>An error occurred while processing the data: {error.message}</p>
77
+ </main>
78
+ );
79
+ }
80
  }