diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c7bd506f0743e0d1c29ab399a98c13b0f10291b2 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# magic program + +> I don't know what's this shitty program doing. I was forced to write it. + +`./main.py` is named as PROGRAM ALPHA, and `summerize-part-list/main.py` is named as PROGRAM BETA. (Because the program sucks, and too difficult to name them) + +Firstly, run PROGRAM BETA to generate one dir (with some pdf-s), one sheet (as the input of ALPHA), and another csv (containing errors). + +Then run ALPHA to get the final result. + diff --git a/summerize-part-list/beta2alpha.py b/summerize-part-list/beta2alpha.py new file mode 100644 index 0000000000000000000000000000000000000000..8031e91f4b8f7324ea78398dd7fe1d86f42c0121 --- /dev/null +++ b/summerize-part-list/beta2alpha.py @@ -0,0 +1,27 @@ +def _stoi(s): + # string to int + return 0 if (s is None or s == '') else int(float(s)) + + +# convert BETA output csv, to match the format of ALPHA input format. +def csv_beta2alpha(csvText): + lines = csvText.split('\n') + res = lines[0] + ',总数é‡(autogen), __uniqer_begin__\n' # Silly M$ office don't like \r\n. + + for line in lines[1:]: + items = line.split(',') + if len(items) <= 1: + continue # empty line + if len(items) != 13: + raise RuntimeError('Invalid line while performing BETA => ALPHA: ' + line) + + actual_quantity = str(_stoi(items[3]) * _stoi(items[4])) + res += '{},{}\n'.format(line.replace('"""','"'), actual_quantity) + + res += '__uniqer_end__\n' + return res + + + + + diff --git a/summerize-part-list/main.py b/summerize-part-list/main.py index 2913c3c12e3f8861a0c17fdcc37c3412bcc38b28..f8d945b0f41648aec1d5aa4b262d503214d85cc0 100755 --- a/summerize-part-list/main.py +++ b/summerize-part-list/main.py @@ -37,6 +37,7 @@ import config, xlsx_conv, io import csv_preprocess import numpy as np from utils import * +import beta2alpha csv_buf = io.StringIO() import logging @@ -81,8 +82,8 @@ def _main(): with open(output_prefix + '.csv', 'w+') as f: # Force windows NT use Linux LF. M$ office don't like CRLF csv. - f.write('åºå·,,,套数,å•套数é‡,é›¶ä»¶åç§°,ææ–™è§„æ ¼,傿•°A,傿•°B,傿•°C,长度,å•ä»¶é‡,备注\n') - f.write(csv_buf.getvalue().replace('\r\n', '\n')) + msg = 'åºå·,,,套数,å•套数é‡,é›¶ä»¶åç§°,ææ–™è§„æ ¼,傿•°A,傿•°B,傿•°C,长度,å•ä»¶é‡,备注\n' + csv_buf.getvalue().replace('\r\n', '\n') + f.write(beta2alpha.csv_beta2alpha(msg)) with open(output_prefix + '-缺失零件.csv', 'w+') as f: # Force windows NT use Linux LF. M$ office don't like CRLF csv. f.write('\n'.join(missing_parts))