Skip to content

Commit c09564a

Browse files
committed
add: 取りこぼし情報を追加
1 parent db76a4e commit c09564a

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,22 @@ enum Day {
6464
Thu = '',
6565
Fri = '',
6666
Sat = '',
67+
Intensive = '集中',
6768
Unknown = '不明'
6869
}
70+
6971
```
7072

7173
### Lecture
7274
```typescript
7375
interface Lecture {
7476
lectureCode: string
7577
name: string
78+
credits: number
79+
overview: string
80+
remarks: string
81+
type: number
82+
year: number[]
7683
details: {
7784
module: Module
7885
day: Day

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "twinte-parser",
3-
"version": "1.2.3",
3+
"version": "1.3.0",
44
"description": "Twinte内部で使用するために開発されたKdBパーサ",
55
"private": false,
66
"main": "dist/index.js",

src/parser.ts

+30
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ const analyzeDayAndPeriod = (str: string): { day: Day; period: number }[] => {
4040
}
4141
})
4242

43+
if (//gm.test(str))
44+
result.push({
45+
day: Day.Intensive,
46+
period: 0
47+
})
48+
4349
//どのテストにも合格しなかったが空文字でなければ仮にunknownとする
4450
if (str !== '' && result.length === 0)
4551
result.push({ day: Day.Unknown, period: 0 })
@@ -79,6 +85,25 @@ const analyzeModule = (str: string): Module[] => {
7985
return result
8086
}
8187

88+
/**
89+
* 標準履修年次の文字列
90+
* '1' '1・2' '1 - 3' 等を解析して
91+
* [1], [1,2], [1,2,3] のような配列で返す
92+
* @param str 解析する文字列
93+
*/
94+
const analyzeYear = (str: string): number[] => {
95+
const res: number[] = []
96+
const seqRes = /(\d) - (\d)/gm.exec(str)
97+
if (seqRes) {
98+
for (let i = Number(seqRes[1]); i <= Number(seqRes[2]); i++) {
99+
res.push(i)
100+
}
101+
} else {
102+
res.push(...str.split('・').map(e => Number(e)))
103+
}
104+
return res
105+
}
106+
82107
/**
83108
* CSVをパースする
84109
* @param csv KDBからダウンロードしたcsv文字列
@@ -99,6 +124,11 @@ export default (csv: string): Lecture[] => {
99124
const classData: Lecture = {
100125
lectureCode: columns[0],
101126
name: columns[1],
127+
credits: Number(columns[3]),
128+
type: Number(columns[2]),
129+
overview: columns[9],
130+
remarks: columns[10],
131+
year: analyzeYear(columns[4]),
102132
details: [],
103133
instructor: columns[8]
104134
}

src/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
export interface Lecture {
22
lectureCode: string
33
name: string
4+
credits: number
5+
overview: string
6+
remarks: string
7+
type: number
8+
year: number[]
49
details: {
510
module: Module
611
day: Day
@@ -31,5 +36,6 @@ export enum Day {
3136
Thu = '木',
3237
Fri = '金',
3338
Sat = '土',
39+
Intensive = '集中',
3440
Unknown = '不明'
3541
}

0 commit comments

Comments
 (0)