hungtcs / traditional-chinese-calendar-database Goto Github PK
View Code? Open in Web Editor NEW:calendar: **农历数据库 1901~2100年
Home Page: https://hungtcs.github.io/traditional-chinese-calendar-database/examples/index.html
License: MIT License
:calendar: **农历数据库 1901~2100年
Home Page: https://hungtcs.github.io/traditional-chinese-calendar-database/examples/index.html
License: MIT License
目前采用的二进制数据文件大小约为357KB
,
这个体积对于通过网络加载的浏览器来说还是比较耗时的,通过参考其他相关资源和资料,
目前的数据还是可以进一步精简的,目前临时的方案为,保留必要的特征数据,
删除可以通过计算推导的数据。数据结构暂定如下。
变量 | 解释 | 意义 | 长度(bit) | 备注 |
---|---|---|---|---|
losm | long or short months | 12个月的大小 | 12 | |
lemo | leap month | 闰月 | 4 | |
lems | (L)leap month long or short | 闰月是大还是小 | 1 | |
fdgd | first day of gregorian date | 正月初一对应的公历日 | 5 | |
fdgm | first day of gregorian month | 正月初一对应的公历月 | 4 | |
fdgy | first day of gregorian year | 正月初一对应的公历年 | 8 | 减去1900得到的数字 |
0x F F F F F F F F F F
0b|0000 0000|0000 0000|0000 0000|0000 0000|0000 0000|
losm lemo L fdgd fdgm fdgy
一年的数据占5B,1901年至2100年共5 * (2100 - 1901)
为995B
。
比如1902年2月5日应该是辛丑年 而数据表里面是壬寅年
要满足真实场景使用的话,有小部分数据是需要修正的(如繁简转换,属相不准确等)。我自己通过数据库方式做了修正,语句如下:
CREATE TABLE
tmp_calendar(
dayvarchar(255) DEFAULT NULL,
gregorianYearvarchar(255) DEFAULT NULL,
gregorianMonthvarchar(255) DEFAULT NULL,
gregorianDatevarchar(255) DEFAULT NULL,
lunarYearvarchar(255) DEFAULT NULL,
lunarMonthvarchar(255) DEFAULT NULL,
lunarDatevarchar(255) DEFAULT NULL,
lunarLeapMonthvarchar(255) DEFAULT NULL,
solarTermvarchar(255) DEFAULT NULL,
zodiac` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
#导入
LOAD DATA INFILE '/path-to/all.csv'
INTO TABLE tmp_calendar
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
#修正
UPDATE tmp_calendar
SET lunarMonth=REPLACE(lunarMonth, '閏', '闰');
UPDATE tmp_calendar
SET solarTerm=REPLACE(solarTerm, '驚蟄', '惊蛰');
UPDATE tmp_calendar
SET solarTerm=REPLACE(solarTerm, '穀雨', '谷雨');
UPDATE tmp_calendar
SET solarTerm=REPLACE(solarTerm, '小滿', '小满');
UPDATE tmp_calendar
SET solarTerm=REPLACE(solarTerm, '芒種', '芒种');
UPDATE tmp_calendar
SET solarTerm=REPLACE(solarTerm, '處暑', '处暑');
UPDATE tmp_calendar
SET zodiac=REPLACE(zodiac, '龍', '龙');
UPDATE tmp_calendar
SET zodiac=REPLACE(zodiac, '馬', '马');
UPDATE tmp_calendar
SET zodiac=REPLACE(zodiac, '雞', '鸡');
UPDATE tmp_calendar
SET zodiac=REPLACE(zodiac, '豬', '猪');
UPDATE tmp_calendar
SET zodiac=REPLACE(zodiac, '犬', '狗');
UPDATE tmp_calendar
SET zodiac='鸡' WHERE zodiac='' AND lunarYear LIKE '%酉';
#重新导出
SELECT 'day','gregorianYear','gregorianMonth','gregorianDate','lunarYear','lunarMonth','lunarDate','lunarLeapMonth','solarTerm','zodiac' FROM DUAL
UNION
SELECT day,gregorianYear,gregorianMonth,gregorianDate,lunarYear,lunarMonth,lunarDate,lunarLeapMonth,solarTerm,zodiac FROM tmp_calendar
INTO OUTFILE '/path-to/new.csv'
FIELDS
TERMINATED BY ','
LINES
TERMINATED BY '\n';
DROP TABLE tmp_calendar
;
`
缺少好多年分的12月31日的数据
为了进一步压缩数据文件的大小,考虑新增二进制的数据格式。
初步概定为:每5个字节(40个bit)代表一天。
名称(从最高位到最低位排序) | 位长度 | 备注 |
---|---|---|
公历年 | 8 | 实际年份为当前年份 - 1900 ,如2020年 数据为2020-1900=120(0x78) |
公历月 | 4 | 如12月 为 0xC |
公历日期 | 5 | 占5个bit |
天干 | 4 | 索引值,如甲 为0B0 |
地支 | 4 | 索引值,如子 为0B0 |
农历月 | 4 | 如十一月 为0B1011 |
农历日期 | 5 | 占5个bit |
是否闰月 | 1 | 第1个字节的第6个bit,闰月为0B1 |
二十四节气 | 5 | 第1个字节的前5个bit,没有节气填充0B00000 |
去掉了星期
和生肖
数据,星期
可以从公历日期计算,生肖
和地支
对应。
例如:2020-12-15 庚子 十一月 初一 非闰月 无节气
0b 0111 1000 1100 0111 1011 0000 0101 1000 0100 0000
0x 7 8 C 7 B 0 5 8 4 0
用逗号按意义隔开位:
0b 0111 1000, 1100, 0111 1,011 0,000 0,101 1,000 01,0,0 0000
0x 7 8 C 7 B 0 5 8 4 0
对应到Uint8Array数组
new Uint8Array([0x78, 0xC7, 0xB0, 0x58, 0x40])
将所有数据按每天5个字节的形式,依次排列,写入到单个二进制文件,从1901年1月1日到2100年12月31日,共73048
天
(new Date('2100-12-31') - new Date('1901-01-01')) / 1000 / 60 / 60 / 24
// 73048
每天占5个字节,那么总大小为73048 * 5
个字节,即365.24KB
。对比csv文件(3.5M)和json文件(11M)有非常明显的提升。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.