Skip to content

Commit 1be57aa

Browse files
Merge pull request #128 from ZDK-UTsukuba/add-2025-kdb-data
2025年度のKdBリニューアルに対応したデータにした。
2 parents 5a6843f + 8ac738a commit 1be57aa

File tree

3 files changed

+71
-42
lines changed

3 files changed

+71
-42
lines changed

src/components/ClassListItem.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ const calcAve = (numOrObj: number | { sum: number; count: number }) => {
3030
: numOrObj.sum / numOrObj.count;
3131
};
3232
33-
const colleges: string[] =
34-
subject.type === "体育" ? [subject.subject_category] : [];
33+
const colleges: string[] = [
34+
...new Set(kdbs.map((v) => v.affiliation.name)),
35+
].flatMap((v) => (v ? [v] : []));
3536
const teachers: {
3637
name: string;
3738
image?: string;

src/content/subjectsSchema.ts

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ type Module =
1919
| "springVacation";
2020
type ModuleTimeTable = Record<Module, readonly TimeTable[]>;
2121

22-
type Hierarchy = readonly { value: string | null; text: string }[];
22+
type Requisite = {
23+
id: string;
24+
name: string;
25+
hasLower: boolean;
26+
} | null;
2327

2428
type InstructionalType = {
2529
text: string;
@@ -33,56 +37,67 @@ type InstructionalType = {
3337
};
3438

3539
type MergedSubject = {
36-
code: string;
37-
name: string;
40+
code: string; // 科目番号
41+
name: string; // 科目名
42+
syllabusLatestLink: string | null; // シラバス最新リンク
3843
instructionalType: {
3944
value: InstructionalType | null;
4045
kdbRaw: string | null;
41-
};
46+
}; // 授業方法
4247
credits: {
4348
value:
4449
| {
45-
type: "number";
50+
type: "normal";
4651
value: number;
4752
}
4853
| {
4954
type: "none";
5055
}
56+
| {
57+
type: "unknown";
58+
}
5159
| null;
5260
kdbRaw: string | null;
53-
};
61+
}; // 単位数
5462
year: {
55-
value: number[];
63+
value:
64+
| {
65+
type: "normal";
66+
value: readonly number[];
67+
}
68+
| {
69+
type: "unknown";
70+
};
5671
kdbRaw: string | null;
5772
twinsRaw: string | null;
58-
};
73+
}; // 標準履修年次
5974
terms: {
60-
term: Terms | null;
61-
module: string | null;
62-
weekdayAndPeriod: string | null;
63-
moduleTimeTable: ModuleTimeTable | null;
75+
term: Terms | null; // 学期
76+
module: string | null; // 実施学期
77+
weekdayAndPeriod: string | null; // 曜時限
78+
moduleTimeTable: ModuleTimeTable | null; // モジュール時間割
6479

6580
twinsRaw: {
6681
term: string;
6782
module: string;
6883
} | null;
6984
};
70-
classroom: null;
85+
classroom: null; // 教室
7186
instructor: {
7287
value: string[];
7388

7489
kdbRaw: string | null;
7590
twinsRaw: string | null;
76-
};
77-
overview: string | null;
78-
remarks: string | null;
79-
auditor: string | null;
80-
conditionsForAuditors: string | null;
91+
}; // 担当教員
92+
overview: string | null; // 授業概要
93+
remarks: string | null; // 備考
94+
auditor: string | null; // 科目等履修生申請可否
95+
conditionsForAuditors: string | null; // 申請条件
8196
exchangeStudent: string | null;
82-
conditionsForExchangeStudents: string | null;
83-
JaEnCourseName: string | null;
84-
parentNumber: string | null;
85-
parentCourseName: string | null;
97+
conditionsForExchangeStudents: string | null; // 申請条件
98+
JaEnCourseName: string | null; // 英語(日本語)科目名
99+
parentNumber: string | null; // 科目コード
100+
parentCourseName: string | null; // 要件科目名
86101

87102
affiliation: {
88103
name: string | null;
@@ -94,9 +109,7 @@ type MergedSubject = {
94109
} | null;
95110
};
96111

97-
kdbDataUpdateDate: string | null;
98-
99-
hierarchy: Hierarchy[];
112+
requisite: Requisite[];
100113
};
101114

102115
const TermsSchema = z.union([
@@ -139,9 +152,13 @@ const ModuleTimeTableSchema = z.object({
139152
fallC: z.array(TimeTableSchema),
140153
springVacation: z.array(TimeTableSchema),
141154
});
142-
const HierarchySchema = z.array(
143-
z.object({ value: z.string().nullable(), text: z.string() }),
144-
);
155+
const RequisiteSchema = z
156+
.object({
157+
id: z.string(),
158+
name: z.string(),
159+
hasLower: z.boolean(),
160+
})
161+
.nullable();
145162
const InstructionalTypeSchema = z.object({
146163
text: z.string(),
147164
flags: z.object({
@@ -155,6 +172,7 @@ const InstructionalTypeSchema = z.object({
155172
const MergedSubjectSchema = z.object({
156173
code: z.string(),
157174
name: z.string(),
175+
syllabusLatestLink: z.string().nullable(),
158176
instructionalType: z.object({
159177
value: InstructionalTypeSchema.nullable(),
160178
kdbRaw: z.string().nullable(),
@@ -163,16 +181,23 @@ const MergedSubjectSchema = z.object({
163181
value: z
164182
.union([
165183
z.object({
166-
type: z.literal("number"),
184+
type: z.literal("normal"),
167185
value: z.number(),
168186
}),
169187
z.object({ type: z.literal("none") }),
188+
z.object({ type: z.literal("unknown") }),
170189
])
171190
.nullable(),
172191
kdbRaw: z.string().nullable(),
173192
}),
174193
year: z.object({
175-
value: z.array(z.number()),
194+
value: z.union([
195+
z.object({
196+
type: z.literal("normal"),
197+
value: z.array(z.number()),
198+
}),
199+
z.object({ type: z.literal("unknown") }),
200+
]),
176201
kdbRaw: z.string().nullable(),
177202
twinsRaw: z.string().nullable(),
178203
}),
@@ -220,7 +245,7 @@ const MergedSubjectSchema = z.object({
220245

221246
kdbDataUpdateDate: z.string().nullable(),
222247

223-
hierarchy: z.array(HierarchySchema),
248+
requisite: z.array(RequisiteSchema),
224249
});
225250

226251
const SubjectsSchema = z.array(MergedSubjectSchema);
@@ -229,8 +254,8 @@ const parsedSubjects: readonly MergedSubject[] = (() => {
229254
try {
230255
return SubjectsSchema.parse(subjectsMergedJson);
231256
} catch (error) {
232-
console.error("Failed to parse subjects:", JSON.stringify(error, null, 4));
233-
throw new Error("Failed to parse subjects");
257+
// console.error("Failed to parse subjects:", JSON.stringify(error, null, 4));
258+
throw new Error("Failed to parse subjects", { cause: error });
234259
}
235260
})();
236261

src/pages/details/[id].astro

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ const params =
119119
<div class={pageStyles.body}>
120120
<h1 class={pageStyles.title}>{subject.name}</h1>
121121
{
122-
subject.type === "体育" && (
123-
<span class={pageStyles.category}>{subject.subject_category}</span>
122+
[...new Set(kdbs.map((v) => v.affiliation.name))].map(
123+
(v) => v && <span class={pageStyles.category}>{v}</span>,
124124
)
125125
}
126126
{
@@ -507,17 +507,20 @@ const params =
507507
<div class={pageStyles.item}>
508508
<div class={pageStyles.label}>単位</div>
509509
<div class={pageStyles.content}>
510-
{kdbSubject.credits.value === null
510+
{kdbSubject.credits.value === null ||
511+
kdbSubject.credits.value.type === "unknown"
511512
? ""
512-
: kdbSubject.credits.value.type === "number"
513-
? kdbSubject.credits.value?.value
514-
: "-"}
513+
: kdbSubject.credits.value.type === "none"
514+
? "-"
515+
: kdbSubject.credits.value.value}
515516
</div>
516517
</div>
517518
<div class={pageStyles.item}>
518519
<div class={pageStyles.label}>標準履修年次</div>
519520
<div class={pageStyles.content}>
520-
{kdbSubject.year.value.join(", ")}
521+
{kdbSubject.year.value.type === "unknown"
522+
? "-"
523+
: kdbSubject.year.value.value.join(", ")}
521524
</div>
522525
</div>
523526
<div class={pageStyles.item}>

0 commit comments

Comments
 (0)