Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cjybyjk committed Jan 4, 2024
0 parents commit 4cae7c7
Show file tree
Hide file tree
Showing 11 changed files with 4,251 additions and 0 deletions.
21 changes: 21 additions & 0 deletions about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div style="padding: 0 24px;">
<h2></h2>
<p>本项目<span style="font-weight: bold;">不是</span>小米官方项目。</p>
<p>答案为用户收集整理,不一定完全正确,欢迎通过 Pull Request 和 issues 提交你的答案。</p>
<p>实际答题中题目和选项可能会发生变化,请注意题目和选项的细节。</p>
<p>祝你们每个人都能天天签到 12 分,早日通过申请审批,解锁 BootLoader。</p>
<p>
开发: <a href="https://github.com/cjybyjk">Shelling</a>
<br/>
数据整理:<a href="https://github.com/MlgmXyysd">MlgmXyysd</a>
</p>
<p>
Buy me a coffee:
<ul>
<li><a href="https://afdian.net/@MlgmXyysd" target="_blank">爱发电</a></li>
<li><a onclick="showImageDialog('支付宝红包', '打开支付宝【扫一扫】', 'img/alipay.jpg')" href="#">支付宝红包</a></li>
</ul>
</p>
<img src="https://img.shields.io/github/stars/MlgmXyysd/Xiaomi-BootLoader-Questionnaire.svg?style=social" alt="GitHub stars">
<img src="https://img.shields.io/github/forks/MlgmXyysd/Xiaomi-BootLoader-Questionnaire.svg?style=social" alt="GitHub forks">
</div>
51 changes: 51 additions & 0 deletions css/ui.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
body {
margin: 0;
font-family: Roboto, Noto Sans SC, PingFang SC, Lantinghei SC, Microsoft Yahei, Hiragino Sans GB, "Microsoft Sans Serif", WenQuanYi Micro Hei, sans-serif;
word-wrap: break-word;
}

mdui-layout {
height: 100vh;
}

mdui-layout-main {
position: relative;
height: 100%;
overflow: hidden;
}

mdui-top-app-bar {
position: absolute;
top: 0px;
right: 0px;
left: 0px;
}

mdui-navigation-drawer {
position: absolute;
top: 64px;
bottom: 0px;
left: 0px;
}

#collapse {
margin: 12px 0;
overflow-y: auto;
max-height: calc(100% - 64px - 12px);
}

h1, h2, h3, h4, h5, h6 {
margin-top: 0;
margin-bottom: 1.25em;
font-weight: 400;
}

h1 {
font-size: 2.5em;
line-height: 1.2;
}

h2 {
font-size: 1.875em;
line-height: 1.3;
}
145 changes: 145 additions & 0 deletions data-tools/convert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import json
import os
import time
import re

def read_problems():
# read problems.json
with open('problems.json', 'r', encoding='utf-8') as f:
problems = json.load(f)
return problems

def read_today():
# read all jsons in 'today' folder
today_problems = []

for filename in os.listdir('today'):
with open(os.path.join('today', filename), 'r', encoding='utf-8') as f:
today_problems.append(json.load(f))
return today_problems

def cleanup_string(string):
# remove <span> tags by using regex
string = re.sub(r'<.*?span.*?>', '', string)
string = string.strip()
return string

def levenshtein_distance(s1, s2):
# calculate levenshtein distance between two strings
# https://en.wikipedia.org/wiki/Levenshtein_distance
if len(s1) < len(s2):
return levenshtein_distance(s2, s1)
if len(s2) == 0:
return len(s1)
previous_row = range(len(s2) + 1)
for i, c1 in enumerate(s1):
current_row = [i + 1]
for j, c2 in enumerate(s2):
insertions = previous_row[j + 1] + 1
deletions = current_row[j] + 1
substitutions = previous_row[j] + (c1 != c2)
current_row.append(min(insertions, deletions, substitutions))
previous_row = current_row
return previous_row[-1]

def update_problems(problems, today_problems):
current_date = time.strftime("%Y-%m-%d", time.localtime())
problems['latest'] = {
'date': current_date,
'problems': []
}
problem_list = problems['problems']
latest_problems = problems['latest']['problems']

# update problems.json
for today_problem in today_problems:
if today_problem['data']['content'] is None:
continue
problem_content = cleanup_string(today_problem['data']['content'])
note = cleanup_string(today_problem['data']['note'])

# find existing problem
problem = None
for p in problem_list:
if p['content'] == problem_content:
problem = p
break
if problem == None:
# create new problem
problem = {
'id': len(problem_list) + 1,
'content': problem_content,
'note': note if note != '' else None,
"type": "single" if today_problem['data']['type'] == 1 else "upload_file" if today_problem['data']['type'] == 12 else "multiple",
'options': []
}
problem_list.append(problem)

# add to latest_problems
latest_problem = {
'id': problem['id'],
'index': today_problem['data']['index'],
'random_options': today_problem['data']['config']['isRandom'] == 1,
'options': []
}
latest_problems.append(latest_problem)

# add options
for option in today_problem['data']['choice']:
option_content = cleanup_string(option['content'])

# find existing option
option = None
for o in problem['options']:
if o['content'] == option_content:
option = o
break
if option == None:
# create new option
print('New option in problem "' + problem_content + '": ' + option_content)

# find nearest option in other problems
nearest_option = None
nearest_option_problem = None
old_distance_option = 10
for p in problem_list:
for o in p['options']:
distance = levenshtein_distance(o['content'], option_content)
if distance < old_distance_option:
old_distance_option = distance
nearest_option = o
nearest_option_problem = p

if nearest_option != None:
print('Nearest option: ' + nearest_option['content'])
print('\tProblem: ' + nearest_option_problem['content'])
print('\tCorrect: ' + str(nearest_option['correct']))
print('\tExplanation: ' + nearest_option['explanation'])

correct = input("该选项是否应选中?(y/n): ")
explanation = input("该选项的解释:")
option = {
'id': len(problem['options']) + 1,
'content': option_content,
'correct': True if correct == 'y' else False,
'explanation': explanation
}
problem['options'].append(option)

latest_problem['options'].append(option['id'])

latest_problems.sort(key=lambda x: x['index'])

def write_problems(problems):
# write problems.json
with open('problems.json', 'w', encoding='utf-8') as f:
json.dump(problems, f, ensure_ascii=False, indent=2)

def main():
problems = read_problems()
today_problems = read_today()
update_problems(problems, today_problems)
write_problems(problems)

if __name__ == '__main__':
main()
Loading

0 comments on commit 4cae7c7

Please sign in to comment.