开始组建财报数据表,过程中有必要做一些注释说明字段,比如资产负债表中为了压缩存储空间,现金等字段单位用kdollar。 差了下操作如下:
创建表过程中
mysql> cash_equiv int null comment 'Cash and Equivalents (kdollars)',
修改表过程中
mysql> alter table eqbalance_sheet modify column invest int comment 'Investments (Deficit, kdollars)';
添加字段过程中
alter table eq_balance_sheet add other_income int comment 'Accumulated Other Comprehensive Income (kdollars)';
查看说明:
mysql> show full columns from eq_balance_sheet;
+----------------+-------------+-----------------+------+-----+---------+-------+---------------------------------+---------------------------------------------------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+----------------+-------------+-----------------+------+-----+---------+-------+---------------------------------+---------------------------------------------------+
| rhid | char(36) | utf8_general_ci | NO | PRI | NULL | | select,insert,update,references | |
| symbol | varchar(10) | utf8_general_ci | NO | | NULL | | select,insert,update,references | |
| cash_equiv | int(11) | NULL | YES | | NULL | | select,insert,update,references | Cash and Equivalents (kdollars) |
| invest_curr | int(11) | NULL | YES | | NULL | | select,insert,update,references | Investments Current (kdollars) |
| cash_st_invest | int(11) | NULL | YES | | NULL | | select,insert,update,references | Cash and Short Term Investments (kdollars) |
| receivables | int(11) | NULL | YES | | NULL | | select,insert,update,references | Trade and Non-Trade Receivables (kdollars) |
| inventory | int(11) | NULL | YES | | NULL | | select,insert,update,references | Inventory (kdollars) |
| curr_ast | int(11) | NULL | YES | | NULL | | select,insert,update,references | Current Assets (kdollars) |
| ppe_net | int(11) | NULL | YES | | NULL | | select,insert,update,references | Property, Plant & Equipment Net (kdollars) |
| goodwill | int(11) | NULL | YES | | NULL | | select,insert,update,references | Goodwill and Intangible Assets (kdollars) |
| invst_ncurr | int(11) | NULL | YES | | NULL | | select,insert,update,references | Investments Non-Current (kdollars) |
| tax_ast | int(11) | NULL | YES | | NULL | | select,insert,update,references | Tax Assets (kdollars) |
| ast_ncurr | int(11) | NULL | YES | | NULL | | select,insert,update,references | Assets Non-Current (kdollars) |
| total_ast | int(11) | NULL | YES | | NULL | | select,insert,update,references | Total Assets (kdollars) |
| payables | int(11) | NULL | YES | | NULL | | select,insert,update,references | Trade and Non-Trade Payables (kdollars) |
| debt_curr | int(11) | NULL | YES | | NULL | | select,insert,update,references | Debt Current (kdollars) |
| curr_liab | int(11) | NULL | YES | | NULL | | select,insert,update,references | Current Liabilities (kdollars) |
| debt_ncurr | int(11) | NULL | YES | | NULL | | select,insert,update,references | Debt Non-Current (kdollars) |
| total_debt | int(11) | NULL | YES | | NULL | | select,insert,update,references | Total Debt (kdollars) |
| def_revenue | int(11) | NULL | YES | | NULL | | select,insert,update,references | Deferred Revenue (kdollars) |
| tax_liab | int(11) | NULL | YES | | NULL | | select,insert,update,references | Tax Liabilities (kdollars) |
| dep_liab | int(11) | NULL | YES | | NULL | | select,insert,update,references | Deposit Liabilities (kdollars) |
| liab_ncurr | int(11) | NULL | YES | | NULL | | select,insert,update,references | Liabilities Non-Current (kdollars) |
| total_liab | int(11) | NULL | YES | | NULL | | select,insert,update,references | Total Liabilities (kdollars) |
| other_income | int(11) | NULL | YES | | NULL | | select,insert,update,references | Accumulated Other Comprehensive Income (kdollars) |
| ret_earning | int(11) | NULL | YES | | NULL | | select,insert,update,references | Accumulated Retained Earnings (Deficit, kdollars) |
| equity | int(11) | NULL | YES | | NULL | | select,insert,update,references | Shareholders Equity (Deficit, kdollars) |
| invest | int(11) | NULL | YES | | NULL | | select,insert,update,references | Investments (Deficit, kdollars) |
+----------------+-------------+-----------------+------+-----+---------+-------+---------------------------------+---------------------------------------------------+
28 rows in set (0.00 sec)
终于把基本的数据库组织结构学的差不多啦,上午拖着需要补充的市场数据,测试导入数据!
python3使用pymysql模块连接InnoDB数据库,连接过程中需要用户名密码,可是明文密码再上传github这是找死,决定研究下简单的加密解密过程,从外部读取密文,再decode后给入。
加密算法分对称加密和非对称加密。对称加密很好理解,就是经典的凯撒密码的套路,采用同样的密钥加密和解密(字幕平移法则)。
DES是经典的对称加密算法,64bits为单位然后套轮函数循环,但是DES目前已经被攻破,三重DES(密钥1加密,密钥2解密,密钥3加密)还有应用价值。 AES是取代DES的算法,具体步骤为替换(SubBytes),ShiftRows(平移),MixColumns(混列),最后AddRoundKey(与原数据异或)。此为一轮AES。 如果采用对称加密,推荐AES算法。
公钥加密是密码学领域非常牛逼的技术,即加密密钥和解密密钥可以不同,这样可以避免密钥配送过程中的风险。公钥丢失也不怕,神不神奇?
比如用户浏览器和server之间非对称加密过程可以是这样:server给公钥,用户用公钥加密,将密文给server(公钥、密文都被窃取也无法获得明文),server将密文用私钥解密。 经典非对称加密算法RSA。其数学原理在阮一峰的网站有介绍。不再赘述。
以我们的应用情景来说,因为不涉及通讯,直接AES对称加密即可。
构建如下类解决:
class AESCipher(object):
def __init__(self, key):
self.bs = 32
self.key = hashlib.sha256(key.encode()).digest()
def encrypt(self, raw):
raw = self._pad(raw)
iv = Random.new().read(AES.block_size)
cipher = AES.new(self.key, AES.MODE_CBC, iv)
return base64.b64encode(iv + cipher.encrypt(raw))
def decrypt(self, enc):
enc = base64.b64decode(enc)
iv = enc[:AES.block_size]
cipher = AES.new(self.key, AES.MODE_CBC, iv)
return self._unpad(cipher.decrypt(enc[AES.block_size:])).decode('utf-8')
def _pad(self, s):
return s + (self.bs - len(s) % self.bs) * chr(self.bs - len(s) % self.bs)
@staticmethod
def _unpad(s):
return s[:-ord(s[len(s)-1:])]
Updated 2018-03-12
今天打算创建Mercurius的数据库,神奇的是,输入create database后报错
ERROR 1006 (HY000): Can’t create database ‘mercurius’ (errno: 28)
换了root账户也不行,查到的信息都是说mysql的数据库权限问题,检查后的确木有问题呀。 注意到google出的关键词errno号不同,很多13号,而我是28号,深度搜索了一番,找到了答案:
This error means that your mysql server does not have enough free space. You need to check the file system size and please remove unwanted software(s) or installers or files.
我去,坑我?磁盘满额?df查看一下,果然/根目录满额。奇怪~
利用find找大文件:
find / -size +800M
发现除了最早丢过来的安装包,就是gdm的log最大,cd过去一看,可了不得,13G的log,应该是图形界面出错后一直在写error,写到了3月5日,果断删掉~并且把安装包移走。目前解决,后面看是否还继续写log。
慎重起见,将mysql的数据库路径进行迁移,然后发现进了个大坑。无论怎样按照网上的步骤调整,都会遇到mysqld服务无法打开的结果。甚至rsync数据库然后做链接都不行。 折腾了一下午,突然想到,不就是把mercurius数据库拿出来么,不动mysql本身的账户库还不行。好吧,最后给mercurius做了链接搞定,要注意所在的上层目录必须有root用户和用户组的读写权限。
Updated 2018-03-11