This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mathdeptv2/工具/手动统计结果转换.ipynb

79 lines
2.6 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"import os,re,json\n",
"\n",
"def form_decimals(string):\n",
" string = re.sub(r\"[\\s]+\",r\"\\t\",string)\n",
" numerals_list = [n for n in string.split(\"\\t\") if len(n)>0]\n",
" for i in range(len(numerals_list)):\n",
" numeral = numerals_list[i]\n",
" str_numeral = \"%.3f\" %float(numeral)\n",
" numerals_list[i] = str_numeral\n",
" return \"\\t\".join(numerals_list)\n",
"\n",
"with open(\"临时文件/统计结果.txt\",\"r\",encoding = \"utf8\") as f:\n",
" data = f.read()\n",
"\n",
"blocks = re.findall(r\"\\[BEGIN\\]([\\s\\S]*?)\\[END\\]\",data)\n",
"\n",
"results_dict = {}\n",
"for block in blocks:\n",
" temp_list = [l.strip() for l in block.split(\"\\n\") if l.strip() != \"\"] \n",
" for line in temp_list:\n",
" if line[:2] == \"##\":\n",
" date = line[2:].strip()\n",
" elif line[:2] == \"**\":\n",
" current_class = line[2:].strip()\n",
" else:\n",
" separating_pos = re.search(\"\\s\",line).span(0)[0]\n",
" if not line[:separating_pos].zfill(6) in results_dict:\n",
" results_dict[line[:separating_pos].zfill(6)] = [date + \"\\t\" + current_class + \"\\t\" + form_decimals(re.sub(\"\\s+?\",\"\\t\",line[separating_pos:])).strip()]\n",
" else:\n",
" results_dict[line[:separating_pos].zfill(6)].append(date + \"\\t\" + current_class + \"\\t\" + form_decimals(re.sub(\"\\s+?\",\"\\t\",line[separating_pos:])).strip())\n",
"\n",
"output_data = \"usages\\n\"\n",
"for id in results_dict:\n",
" output_data += id + \"\\n\"\n",
" output_data += \"\\n\".join(results_dict[id])\n",
" output_data += \"\\n\\n\"\n",
"\n",
"with open(\"临时文件/统计测试.txt\",\"w\",encoding = \"utf8\") as f:\n",
" f.write(output_data)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.8 ('base')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "d311ffef239beb3b8f3764271728f3972d7b090c974f8e972fcdeedf230299ac"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}