Skip to content
Snippets Groups Projects
Commit 2577ac49 authored by Recolic Keghart's avatar Recolic Keghart
Browse files

allow beta2alpha

parent f23cf4c9
No related branches found
No related tags found
No related merge requests found
# 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.
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
...@@ -37,6 +37,7 @@ import config, xlsx_conv, io ...@@ -37,6 +37,7 @@ import config, xlsx_conv, io
import csv_preprocess import csv_preprocess
import numpy as np import numpy as np
from utils import * from utils import *
import beta2alpha
csv_buf = io.StringIO() csv_buf = io.StringIO()
import logging import logging
...@@ -81,8 +82,8 @@ def _main(): ...@@ -81,8 +82,8 @@ def _main():
with open(output_prefix + '.csv', 'w+') as f: with open(output_prefix + '.csv', 'w+') as f:
# Force windows NT use Linux LF. M$ office don't like CRLF csv. # Force windows NT use Linux LF. M$ office don't like CRLF csv.
f.write('序号,,,套数,单套数量,零件名称,材料规格,参数A,参数B,参数C,长度,单件重,备注\n') msg = '序号,,,套数,单套数量,零件名称,材料规格,参数A,参数B,参数C,长度,单件重,备注\n' + csv_buf.getvalue().replace('\r\n', '\n')
f.write(csv_buf.getvalue().replace('\r\n', '\n')) f.write(beta2alpha.csv_beta2alpha(msg))
with open(output_prefix + '-缺失零件.csv', 'w+') as f: with open(output_prefix + '-缺失零件.csv', 'w+') as f:
# Force windows NT use Linux LF. M$ office don't like CRLF csv. # Force windows NT use Linux LF. M$ office don't like CRLF csv.
f.write('\n'.join(missing_parts)) f.write('\n'.join(missing_parts))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment