Skip to content

Commit

Permalink
新增 心情删除功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawnsdaddy committed Jan 16, 2025
1 parent c87f7a1 commit 6edfa60
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 6 deletions.
25 changes: 25 additions & 0 deletions arknights_mower/solvers/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,31 @@ def load_state():
return loaded_state


def clear_data(date_time):
database_path = get_path("@app/tmp/data.db")
try:
connection = sqlite3.connect(database_path)
cursor = connection.cursor()

# Ensure date_time is in the correct format
if isinstance(date_time, datetime):
date_time_str = date_time.strftime("%Y-%m-%d %H:%M:%S")
else:
date_time_str = date_time

# Execute the DELETE statement with parameterized query
cursor.execute(
"DELETE FROM agent_action WHERE `current_time` < ?", (date_time_str,)
)

connection.commit()
connection.close()
logger.info(f"已删除 早于 {date_time_str} 的干员心情记录")

except sqlite3.Error as e:
logger.error(f"SQLite error: {e}")


def get_work_rest_ratios():
# TODO 整理数据计算工休比
database_path = get_path("@app/tmp/data.db")
Expand Down
19 changes: 17 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from werkzeug.exceptions import NotFound

from arknights_mower import __system__, __version__
from arknights_mower.solvers.record import load_state, save_state
from arknights_mower.solvers.record import clear_data, load_state, save_state
from arknights_mower.utils import config
from arknights_mower.utils.datetime import get_server_time
from arknights_mower.utils.log import get_log_by_time, logger
Expand Down Expand Up @@ -384,6 +384,21 @@ def getTradingHistory():
return record.get_trading_history(start_date, end_date)


@app.route("/record/clear-data", methods=["DELETE"])
def clear_data_route():
date_time_str = request.json.get("date_time")
logger.info(date_time_str)
if not date_time_str:
return "日期时间参数缺失", 400
try:
date_time = datetime.datetime.fromtimestamp(date_time_str / 1000.0)
except ValueError:
return "日期时间格式不正确", 400

clear_data(date_time)
return "数据已清除", 200


@app.route("/getwatermark")
def getwatermark():
from arknights_mower.__init__ import __version__
Expand Down Expand Up @@ -675,7 +690,7 @@ def submit_feedback():
logger.info("log 文件发送中,请等待")
if not log_files:
raise ValueError("对应时间log 文件无法找到")
body = f"<p>Bug 发生时间区间:{datetime.datetime.fromtimestamp(req['startTime']/ 1000.0)}--{dt}</p><br><p>{req['description']}</p>"
body = f"<p>Bug 发生时间区间:{datetime.datetime.fromtimestamp(req['startTime'] / 1000.0)}--{dt}</p><br><p>{req['description']}</p>"
else:
body = req["description"]
email = Email(
Expand Down
8 changes: 4 additions & 4 deletions ui/src/pages/Plan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { free_blacklist, theme } = storeToRefs(config_store)
const plan_store = usePlanStore()
const {
ling_xi,
ling_xi,
resting_priority,
exhaust_require,
rest_in_full,
Expand Down Expand Up @@ -100,7 +100,7 @@ function create_sub_plan() {
conf: {
exhaust_require: [],
free_blacklist: [],
ling_xi: ling_xi.value,
ling_xi: ling_xi.value,
rest_in_full: [],
resting_priority: [],
workaholic: [],
Expand Down Expand Up @@ -137,7 +137,7 @@ const current_conf = ref({
watchEffect(() => {
if (sub_plan.value == 'main') {
current_conf.value = {
ling_xi: ling_xi.value,
ling_xi: ling_xi.value,
rest_in_full: rest_in_full.value,
resting_priority: resting_priority.value,
workaholic: workaholic.value,
Expand All @@ -153,7 +153,7 @@ watchEffect(() => {
watchEffect(() => {
if (sub_plan.value == 'main') {
ling_xi.value = current_conf.value.ling_xi
ling_xi.value = current_conf.value.ling_xi
rest_in_full.value = current_conf.value.rest_in_full
exhaust_require.value = current_conf.value.exhaust_require
resting_priority.value = current_conf.value.resting_priority
Expand Down
33 changes: 33 additions & 0 deletions ui/src/pages/RecordPie.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
<template>
<div>
<h1 class="page-title">工作休息比例报表</h1>
<div style="text-align: center; display: flex; justify-content: center; margin-bottom: 20px">
<n-date-picker
v-model:value="selectedTime"
type="datetime"
placeholder="选择时间"
style="width: 200px"
/>
<n-button @click="showConfirm = true">清除时间之前的心情数据</n-button>
</div>
<n-modal
v-model:show="showConfirm"
preset="dialog"
title="确认删除"
content="您确定要删除选择时间之前的所有心情数据吗?该行为不可逆,如有需要,请前往temp文件夹备份db文件"
positive-text="确定"
negative-text="取消"
@positive-click="clearData"
/>
<n-grid
:x-gap="12"
:y-gap="8"
Expand Down Expand Up @@ -36,6 +54,7 @@ import {
Tooltip,
ArcElement
} from 'chart.js'
import axios from 'axios'
const recordStore = useRecordStore()
const { getMoodRatios } = recordStore
Expand Down Expand Up @@ -76,6 +95,20 @@ const pieOptions = ref({
}
}
})
const selectedTime = ref(new Date().getTime())
const showConfirm = ref(false)
const clearData = async () => {
try {
const req = { date_time: selectedTime.value }
await axios.delete(`${import.meta.env.VITE_HTTP_URL}/record/clear-data`, { data: req })
alert('数据已清除')
} catch (error) {
console.error('清除数据失败', error)
alert('清除数据失败,请重试')
} finally {
showConfirm.value = false
}
}
</script>
<style scoped>
Expand Down

0 comments on commit 6edfa60

Please sign in to comment.