Skip to content

Instantly share code, notes, and snippets.

@skyzh
Last active January 29, 2019 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyzh/b5adb665916730d5665720406c67ba61 to your computer and use it in GitHub Desktop.
Save skyzh/b5adb665916730d5665720406c67ba61 to your computer and use it in GitHub Desktop.
Read course data
const data = require('./data.json');
const reg = {
time: /星期(.*?)[ ]+第(.*?)节--第(.*?)节/,
header: /行课安排为第(.*?)-(.*?)周?,其中:/,
loc: /(.*?)\((.*?)-(.*?)周\)[ ]+(.*?)\((.*?)-(.*?)周\)/,
loc_unknown: /[ ]*(.*?)[ ]+(.*?)\((.*?)-(.*?)周\)/,
bi_week: /(单|双)周/
};
const fetch_data = {
header: ["week_start", "week_end"],
time: ["week_day", "course_start", "course_end"],
loc: ["location", "location_start", "location_end",
"teacher", "teacher_start", "teacher_end"],
loc_unknown: ["location", "teacher", "teacher_start", "teacher_end"],
bi_week: ["bi_week"]
}
const _ = require('lodash');
const parse = (regId, line) => {
const data = {};
const match = line.match(reg[regId]);
for (let i = 1; i <= fetch_data[regId].length; i++) {
data[fetch_data[regId][i - 1]] = match[i];
}
return data;
}
const fs = require('fs');
const result = _.map(data, _course => {
const course = _course.split('\n');
const data = {
header: {},
days: {}
};
let current_day = "";
let bi_week = "";
_.forEach(course, line => {
if (reg.header.test(line)) data.header = parse('header', line);
else if (reg.time.test(line)) {
const time = parse('time', line);
current_day = (bi_week == "" ? `${time.week_day}` : `${time.week_day}(${bi_week})`);
data.days[current_day] = {
day: time,
courses: []
}
} else if (reg.loc.test(line)) data.days[current_day].courses.push(parse('loc', line));
else if (reg.loc_unknown.test(line)) data.days[current_day].courses.push(parse('loc_unknown', line));
else if (reg.bi_week.test(line)) bi_week = parse('bi_week', line).bi_week;
});
return data;
});
fs.writeFileSync('result.json', JSON.stringify(result));
[
"行课安排为第,其中:\n星期六 第7节--第10节\n 不安排教室 钟兴军(2-16周)",
"行课安排为第1-11周,其中:\n星期一 第6节--第8节\n不安排教室 潘卫(1-11周)\n不安排教室 宋海艳(1-11周)\n不安排教室 范秀凤(1-11周)\n不安排教室 董文军(1-11周)",
"行课安排为第1-14周,其中:\n星期二 第9节--第10节\n中院105(1-8周) 袁焱(1-14周)\n中院105(1-8周) 陈颖琪(1-14周)\n中院105(1-8周) 李安琪(1-14周)",
"行课安排为第1-14周,其中:\n星期五 第9节--第10节\n东中院2-305(1-8周) 陈颖琪(1-14周)\n东中院2-305(1-8周) 袁焱(1-14周)\n东中院2-305(1-8周) 孟桂娥(1-14周)\n东中院2-305(1-8周) 李安琪(1-14周)",
"行课安排为第1-16周,其中:\n单周\n星期三 第3节--第4节\n东下院304(1-15周) 蔡国平(1-15周)\n星期五 第1节--第2节\n东下院304(1-15周) 蔡国平(1-15周)\n双周\n星期三 第3节--第4节\n东下院304(2-16周) 蔡国平(2-16周)",
"行课安排为第1-16周,其中:\n星期一 第3节--第4节\n东下院211(1-16周) 高圣彬(1-16周)\n东下院211(1-16周) 龚景海(1-16周)",
"行课安排为第1-16周,其中:\n星期一 第3节--第4节\n东中院1-201(1-16周) Peter Bradley Shull(1-16周)\n星期四 第1节--第2节\n东中院1-201(1-16周) Peter Bradley Shull(1-16周)",
"行课安排为第1-16周,其中:\n星期一 第7节--第10节\n东上院107(1-1周) 范文兵(1-16周)\n东上院107(1-1周) 刘小凯(1-16周)\n东上院107(1-1周) 王浩娱(1-16周)\n东上院107(1-1周) 赵冬梅(1-16周)\n星期四 第7节--第10节\n东上院107(1-1周) 范文兵(1-16周)\n东上院107(1-1周) 刘小凯(1-16周)\n东上院107(1-1周) 王浩娱(1-16周)\n东上院107(1-1周) 赵冬梅(1-16周)",
"行课安排为第1-16周,其中:\n星期一 第7节--第8节\n中院105(1-8周) 杨宇红(1-16周)",
"行课安排为第1-16周,其中:\n星期一 第1节--第2节\n下院411(1-16周) 陈建平(1-16周)\n下院411(1-16周) 杨华(1-16周)\n星期四 第3节--第4节\n下院411(1-8周) 陈建平(1-8周)\n下院411(1-8周) 杨华(1-8周)\n",
"行课安排为第1-16周,其中:\n星期三 第1节--第2节\n东下院403(1-16周) 赵继敏(1-16周)\n星期五 第7节--第8节\n东下院403(1-16周) 赵继敏(1-8周)",
"行课安排为第1-16周,其中:\n星期二 第3节--第4节\n东中院3-205(1-16周) 龙宇(1-16周)\n星期五 第7节--第8节\n东中院3-205(1-16周) 龙宇(9-16周)",
"行课安排为第1-16周,其中:\n星期五 第3节--第5节\n东中院2-404(1-8周) 陈彩莲(1-16周)\n东中院2-404(1-8周) 王易因(1-16周)",
"行课安排为第1-16周,其中:\n星期六 第1节--第2节\n 不安排教室 不安排教师",
"行课安排为第1-16周,其中:\n星期四 第1节--第2节\n东中院4-402(1-16周) 顾顺超(1-8周)",
"行课安排为第1-18周,其中:\n星期三 第1节--第2节\n东中院1-109(1-18周) 杨喜军(1-8周)\n星期五 第7节--第8节\n东中院1-109(1-18周) 杨喜军(1-8周)",
"行课安排为第1-18周,其中:\n星期三 第1节--第2节\n东中院4-404(1-18周) 张勇健(1-16周)",
"行课安排为第1-18周,其中:\n星期四 第6节--第8节\n东中院4-304(1-18周) 王开学(1-16周)",
"行课安排为第1-8周,其中:\n星期一 第3节--第4节\n东下院111(1-8周) 许劲松(1-8周)\n星期三 第3节--第4节\n东下院111(1-8周) 许劲松(1-8周)",
"行课安排为第1-8周,其中:\n星期二 第3节--第4节\n东中院4-306(1-8周) 张帆(1-18周)\n星期四 第7节--第8节\n东中院4-306(1-8周) 张帆(1-18周)",
"行课安排为第1-9周,其中:\n星期四 第9节--第10节\n 不安排教室 但文蛟(1-9周)",
"行课安排为第9-16周,其中:\n星期三 第1节--第2节\n东下院111(9-16周) 李英辉(9-16周)\n东下院111(9-16周) 陈炉云(9-16周)\n东下院111(9-16周) 易宏(9-16周)\n星期五 第3节--第4节\n东下院111(9-16周) 李英辉(9-16周)\n东下院111(9-16周) 陈炉云(9-16周)\n东下院111(9-16周) 易宏(9-16周)"
]
[{
"header": {},
"days": {
"六": {
"day": {
"week_day": "六",
"course_start": "7",
"course_end": "10"
},
"courses": [{
"location": "不安排教室",
"teacher": "钟兴军",
"teacher_start": "2",
"teacher_end": "16"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "11"
},
"days": {
"一": {
"day": {
"week_day": "一",
"course_start": "6",
"course_end": "8"
},
"courses": [{
"location": "不安排教室",
"teacher": "潘卫",
"teacher_start": "1",
"teacher_end": "11"
}, {
"location": "不安排教室",
"teacher": "宋海艳",
"teacher_start": "1",
"teacher_end": "11"
}, {
"location": "不安排教室",
"teacher": "范秀凤",
"teacher_start": "1",
"teacher_end": "11"
}, {
"location": "不安排教室",
"teacher": "董文军",
"teacher_start": "1",
"teacher_end": "11"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "14"
},
"days": {
"二": {
"day": {
"week_day": "二",
"course_start": "9",
"course_end": "10"
},
"courses": [{
"location": "中院105",
"location_start": "1",
"location_end": "8",
"teacher": "袁焱",
"teacher_start": "1",
"teacher_end": "14"
}, {
"location": "中院105",
"location_start": "1",
"location_end": "8",
"teacher": "陈颖琪",
"teacher_start": "1",
"teacher_end": "14"
}, {
"location": "中院105",
"location_start": "1",
"location_end": "8",
"teacher": "李安琪",
"teacher_start": "1",
"teacher_end": "14"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "14"
},
"days": {
"五": {
"day": {
"week_day": "五",
"course_start": "9",
"course_end": "10"
},
"courses": [{
"location": "东中院2-305",
"location_start": "1",
"location_end": "8",
"teacher": "陈颖琪",
"teacher_start": "1",
"teacher_end": "14"
}, {
"location": "东中院2-305",
"location_start": "1",
"location_end": "8",
"teacher": "袁焱",
"teacher_start": "1",
"teacher_end": "14"
}, {
"location": "东中院2-305",
"location_start": "1",
"location_end": "8",
"teacher": "孟桂娥",
"teacher_start": "1",
"teacher_end": "14"
}, {
"location": "东中院2-305",
"location_start": "1",
"location_end": "8",
"teacher": "李安琪",
"teacher_start": "1",
"teacher_end": "14"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "16"
},
"days": {
"三(单)": {
"day": {
"week_day": "三",
"course_start": "3",
"course_end": "4"
},
"courses": [{
"location": "东下院304",
"location_start": "1",
"location_end": "15",
"teacher": "蔡国平",
"teacher_start": "1",
"teacher_end": "15"
}]
},
"五(单)": {
"day": {
"week_day": "五",
"course_start": "1",
"course_end": "2"
},
"courses": [{
"location": "东下院304",
"location_start": "1",
"location_end": "15",
"teacher": "蔡国平",
"teacher_start": "1",
"teacher_end": "15"
}]
},
"三(双)": {
"day": {
"week_day": "三",
"course_start": "3",
"course_end": "4"
},
"courses": [{
"location": "东下院304",
"location_start": "2",
"location_end": "16",
"teacher": "蔡国平",
"teacher_start": "2",
"teacher_end": "16"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "16"
},
"days": {
"一": {
"day": {
"week_day": "一",
"course_start": "3",
"course_end": "4"
},
"courses": [{
"location": "东下院211",
"location_start": "1",
"location_end": "16",
"teacher": "高圣彬",
"teacher_start": "1",
"teacher_end": "16"
}, {
"location": "东下院211",
"location_start": "1",
"location_end": "16",
"teacher": "龚景海",
"teacher_start": "1",
"teacher_end": "16"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "16"
},
"days": {
"一": {
"day": {
"week_day": "一",
"course_start": "3",
"course_end": "4"
},
"courses": [{
"location": "东中院1-201",
"location_start": "1",
"location_end": "16",
"teacher": "Peter Bradley Shull",
"teacher_start": "1",
"teacher_end": "16"
}]
},
"四": {
"day": {
"week_day": "四",
"course_start": "1",
"course_end": "2"
},
"courses": [{
"location": "东中院1-201",
"location_start": "1",
"location_end": "16",
"teacher": "Peter Bradley Shull",
"teacher_start": "1",
"teacher_end": "16"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "16"
},
"days": {
"一": {
"day": {
"week_day": "一",
"course_start": "7",
"course_end": "10"
},
"courses": [{
"location": "东上院107",
"location_start": "1",
"location_end": "1",
"teacher": "范文兵",
"teacher_start": "1",
"teacher_end": "16"
}, {
"location": "东上院107",
"location_start": "1",
"location_end": "1",
"teacher": "刘小凯",
"teacher_start": "1",
"teacher_end": "16"
}, {
"location": "东上院107",
"location_start": "1",
"location_end": "1",
"teacher": "王浩娱",
"teacher_start": "1",
"teacher_end": "16"
}, {
"location": "东上院107",
"location_start": "1",
"location_end": "1",
"teacher": "赵冬梅",
"teacher_start": "1",
"teacher_end": "16"
}]
},
"四": {
"day": {
"week_day": "四",
"course_start": "7",
"course_end": "10"
},
"courses": [{
"location": "东上院107",
"location_start": "1",
"location_end": "1",
"teacher": "范文兵",
"teacher_start": "1",
"teacher_end": "16"
}, {
"location": "东上院107",
"location_start": "1",
"location_end": "1",
"teacher": "刘小凯",
"teacher_start": "1",
"teacher_end": "16"
}, {
"location": "东上院107",
"location_start": "1",
"location_end": "1",
"teacher": "王浩娱",
"teacher_start": "1",
"teacher_end": "16"
}, {
"location": "东上院107",
"location_start": "1",
"location_end": "1",
"teacher": "赵冬梅",
"teacher_start": "1",
"teacher_end": "16"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "16"
},
"days": {
"一": {
"day": {
"week_day": "一",
"course_start": "7",
"course_end": "8"
},
"courses": [{
"location": "中院105",
"location_start": "1",
"location_end": "8",
"teacher": "杨宇红",
"teacher_start": "1",
"teacher_end": "16"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "16"
},
"days": {
"一": {
"day": {
"week_day": "一",
"course_start": "1",
"course_end": "2"
},
"courses": [{
"location": "下院411",
"location_start": "1",
"location_end": "16",
"teacher": "陈建平",
"teacher_start": "1",
"teacher_end": "16"
}, {
"location": "下院411",
"location_start": "1",
"location_end": "16",
"teacher": "杨华",
"teacher_start": "1",
"teacher_end": "16"
}]
},
"四": {
"day": {
"week_day": "四",
"course_start": "3",
"course_end": "4"
},
"courses": [{
"location": "下院411",
"location_start": "1",
"location_end": "8",
"teacher": "陈建平",
"teacher_start": "1",
"teacher_end": "8"
}, {
"location": "下院411",
"location_start": "1",
"location_end": "8",
"teacher": "杨华",
"teacher_start": "1",
"teacher_end": "8"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "16"
},
"days": {
"三": {
"day": {
"week_day": "三",
"course_start": "1",
"course_end": "2"
},
"courses": [{
"location": "东下院403",
"location_start": "1",
"location_end": "16",
"teacher": "赵继敏",
"teacher_start": "1",
"teacher_end": "16"
}]
},
"五": {
"day": {
"week_day": "五",
"course_start": "7",
"course_end": "8"
},
"courses": [{
"location": "东下院403",
"location_start": "1",
"location_end": "16",
"teacher": "赵继敏",
"teacher_start": "1",
"teacher_end": "8"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "16"
},
"days": {
"二": {
"day": {
"week_day": "二",
"course_start": "3",
"course_end": "4"
},
"courses": [{
"location": "东中院3-205",
"location_start": "1",
"location_end": "16",
"teacher": "龙宇",
"teacher_start": "1",
"teacher_end": "16"
}]
},
"五": {
"day": {
"week_day": "五",
"course_start": "7",
"course_end": "8"
},
"courses": [{
"location": "东中院3-205",
"location_start": "1",
"location_end": "16",
"teacher": "龙宇",
"teacher_start": "9",
"teacher_end": "16"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "16"
},
"days": {
"五": {
"day": {
"week_day": "五",
"course_start": "3",
"course_end": "5"
},
"courses": [{
"location": "东中院2-404",
"location_start": "1",
"location_end": "8",
"teacher": "陈彩莲",
"teacher_start": "1",
"teacher_end": "16"
}, {
"location": "东中院2-404",
"location_start": "1",
"location_end": "8",
"teacher": "王易因",
"teacher_start": "1",
"teacher_end": "16"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "16"
},
"days": {
"六": {
"day": {
"week_day": "六",
"course_start": "1",
"course_end": "2"
},
"courses": []
}
}
}, {
"header": {
"week_start": "1",
"week_end": "16"
},
"days": {
"四": {
"day": {
"week_day": "四",
"course_start": "1",
"course_end": "2"
},
"courses": [{
"location": "东中院4-402",
"location_start": "1",
"location_end": "16",
"teacher": "顾顺超",
"teacher_start": "1",
"teacher_end": "8"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "18"
},
"days": {
"三": {
"day": {
"week_day": "三",
"course_start": "1",
"course_end": "2"
},
"courses": [{
"location": "东中院1-109",
"location_start": "1",
"location_end": "18",
"teacher": "杨喜军",
"teacher_start": "1",
"teacher_end": "8"
}]
},
"五": {
"day": {
"week_day": "五",
"course_start": "7",
"course_end": "8"
},
"courses": [{
"location": "东中院1-109",
"location_start": "1",
"location_end": "18",
"teacher": "杨喜军",
"teacher_start": "1",
"teacher_end": "8"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "18"
},
"days": {
"三": {
"day": {
"week_day": "三",
"course_start": "1",
"course_end": "2"
},
"courses": [{
"location": "东中院4-404",
"location_start": "1",
"location_end": "18",
"teacher": "张勇健",
"teacher_start": "1",
"teacher_end": "16"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "18"
},
"days": {
"四": {
"day": {
"week_day": "四",
"course_start": "6",
"course_end": "8"
},
"courses": [{
"location": "东中院4-304",
"location_start": "1",
"location_end": "18",
"teacher": "王开学",
"teacher_start": "1",
"teacher_end": "16"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "8"
},
"days": {
"一": {
"day": {
"week_day": "一",
"course_start": "3",
"course_end": "4"
},
"courses": [{
"location": "东下院111",
"location_start": "1",
"location_end": "8",
"teacher": "许劲松",
"teacher_start": "1",
"teacher_end": "8"
}]
},
"三": {
"day": {
"week_day": "三",
"course_start": "3",
"course_end": "4"
},
"courses": [{
"location": "东下院111",
"location_start": "1",
"location_end": "8",
"teacher": "许劲松",
"teacher_start": "1",
"teacher_end": "8"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "8"
},
"days": {
"二": {
"day": {
"week_day": "二",
"course_start": "3",
"course_end": "4"
},
"courses": [{
"location": "东中院4-306",
"location_start": "1",
"location_end": "8",
"teacher": "张帆",
"teacher_start": "1",
"teacher_end": "18"
}]
},
"四": {
"day": {
"week_day": "四",
"course_start": "7",
"course_end": "8"
},
"courses": [{
"location": "东中院4-306",
"location_start": "1",
"location_end": "8",
"teacher": "张帆",
"teacher_start": "1",
"teacher_end": "18"
}]
}
}
}, {
"header": {
"week_start": "1",
"week_end": "9"
},
"days": {
"四": {
"day": {
"week_day": "四",
"course_start": "9",
"course_end": "10"
},
"courses": [{
"location": "不安排教室",
"teacher": "但文蛟",
"teacher_start": "1",
"teacher_end": "9"
}]
}
}
}, {
"header": {
"week_start": "9",
"week_end": "16"
},
"days": {
"三": {
"day": {
"week_day": "三",
"course_start": "1",
"course_end": "2"
},
"courses": [{
"location": "东下院111",
"location_start": "9",
"location_end": "16",
"teacher": "李英辉",
"teacher_start": "9",
"teacher_end": "16"
}, {
"location": "东下院111",
"location_start": "9",
"location_end": "16",
"teacher": "陈炉云",
"teacher_start": "9",
"teacher_end": "16"
}, {
"location": "东下院111",
"location_start": "9",
"location_end": "16",
"teacher": "易宏",
"teacher_start": "9",
"teacher_end": "16"
}]
},
"五": {
"day": {
"week_day": "五",
"course_start": "3",
"course_end": "4"
},
"courses": [{
"location": "东下院111",
"location_start": "9",
"location_end": "16",
"teacher": "李英辉",
"teacher_start": "9",
"teacher_end": "16"
}, {
"location": "东下院111",
"location_start": "9",
"location_end": "16",
"teacher": "陈炉云",
"teacher_start": "9",
"teacher_end": "16"
}, {
"location": "东下院111",
"location_start": "9",
"location_end": "16",
"teacher": "易宏",
"teacher_start": "9",
"teacher_end": "16"
}]
}
}
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment