From 4bc0d59c635f6d4495027c7e3f3c2ba30b0f3010 Mon Sep 17 00:00:00 2001 From: Chunxian Zhang <1836891291@qq.com> Date: Sat, 20 Aug 2022 07:51:39 +0800 Subject: [PATCH] =?UTF-8?q?be=20=E6=9B=B4=E6=96=B0=E5=90=8E=E7=AB=AFAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appTime/AppTime-Realease/data.db-journal | 0 lazy-timer-be/app.py | 111 ++++++++++++++++++++++++++----- lazy-timer-fe/package-lock.json | 48 ++++++++++++- lazy-timer-fe/package.json | 1 + lazy-timer-fe/src/data/dummy.js | 33 ++++----- lazy-timer-fe/src/pages/Ecommerce.jsx | 13 ++-- 6 files changed, 166 insertions(+), 40 deletions(-) create mode 100644 appTime/AppTime-Realease/data.db-journal diff --git a/appTime/AppTime-Realease/data.db-journal b/appTime/AppTime-Realease/data.db-journal new file mode 100644 index 0000000..e69de29 diff --git a/lazy-timer-be/app.py b/lazy-timer-be/app.py index c234fa2..49760ad 100644 --- a/lazy-timer-be/app.py +++ b/lazy-timer-be/app.py @@ -1,23 +1,102 @@ +# python对多文件编程及其不友好, 白写了这么多文件到处报错, 最后还是要写在一个文件里解决了 +import os import sys - +from datetime import datetime # 处理时间 from flask import Flask -from markupsafe import escape # 字符串转义处理 +from flask_cors import CORS, cross_origin from flask_sqlalchemy import SQLAlchemy -# SQLite windows适配 -WIN = sys.platform.startswith('win') -if WIN: - prefix = 'sqlite:///' -else: - prefix = 'sqlite:////' - app = Flask(__name__) -db = SQLAlchemy(app) # 初始化拓展, 传入程序实例 app +cors = CORS(app) +app.config['CORS_HEADERS'] = 'Content-Type' + +prefix = "sqlite:///" +path = '../appTime/AppTime-Realease/data.db' +app.config['SQLALCHEMY_DATABASE_URI'] = prefix + path +app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True +# 在扩展类实例化前加载配置 +db = SQLAlchemy(app) + + +# 数据库模型 +class App(db.Model): + id = db.Column(db.Integer, primary_key=True) # App id + process = db.Column(db.Text) # appName + text = db.Column(db.Text) # app窗口名称 + tagId = db.Column(db.Integer, unique=True) # 标签id + + +class Period(db.Model): + timeStart = db.Column(db.DateTime, primary_key=True) # 开始时间 + timeEnd = db.Column(db.DateTime) # 结束时间 + winId = db.Column(db.Integer) # 活动id + + +class Tag(db.Model): + id = db.Column(db.Integer, primary_key=True) # 标签id + text = db.Column(db.Text) # 标签文本 + + +class Win(db.Model): + id = db.Column(db.Integer, primary_key=True) # 活动id + appId = db.Column(db.Integer) # App id + text = db.Column(db.Text, nullable=True) # 活动窗口名称 + tagId = db.Column(db.Integer, nullable=True) # 标签id + + +# 后端API +# 获取每日屏幕使用总时间 +@app.route('/getDayScreenUseTime', methods=['GET']) +@cross_origin() +def getDayScreenUseTime(): + datetimeStr = '2022-09-05' + struct_time = datetime.strptime(datetimeStr, "%Y-%m-%d").date() # 获取请求日期, struct_time数据类型为dateTime + activityTimeList = Period.query.all() + selectedTimeList = [] # 选中的对应今天日期的时间李彪 + for time in activityTimeList: + if time.timeStart.date() == struct_time: + selectedTimeList.append(time) + + timeAmount = 0 + for time in selectedTimeList: + time_diff = time.timeEnd - time.timeStart + timeAmount = timeAmount + time_diff.total_seconds() + + timeAmount = int(timeAmount) + m, s = divmod(timeAmount, 60) + h, m = divmod(m, 60) + + return '{:d}小时{:02d}分{:02d}秒'.format(h, m, s) + +# 获取每日第一次屏幕使用时刻 +@app.route('/getFirstScreenTime', methods=['GET']) +@cross_origin() +def getFirstScreenTime(): + datetimeStr = '2022-09-05' + struct_time = datetime.strptime(datetimeStr, "%Y-%m-%d").date() # 获取请求日期, struct_time数据类型为dateTime + activityTimeList = Period.query.all() + selectedTimeList = [] # 选中的对应今天日期的时间李彪 + for time in activityTimeList: + if time.timeStart.date() == struct_time: + selectedTimeList.append(time) + break; + + firstScreenTime = selectedTimeList[0].timeStart.strftime('%H点%M分%S秒') + return firstScreenTime + +# 获取每日最后一次屏幕使用时刻 +@app.route('/getLastScreenTime', methods=['GET']) +@cross_origin() +def getLastScreenTime(): + datetimeStr = '2022-09-05' + struct_time = datetime.strptime(datetimeStr, "%Y-%m-%d").date() # 获取请求日期, struct_time数据类型为dateTime + activityTimeList = Period.query.all() + selectedTimeList = [] # 选中的对应今天日期的时间李彪 + for time in activityTimeList: + if time.timeStart.date() == struct_time: + selectedTimeList.append(time) -@app.route('/') -def hello(): - return 'Welcome to My Watchlist!' + lastScreenTime = selectedTimeList[-1].timeEnd.strftime('%H点%M分%S秒') + return lastScreenTime -@app.route('/user/') -def user_page(name): - return f'User: {escape(name)}' +# 持续时间 \ No newline at end of file diff --git a/lazy-timer-fe/package-lock.json b/lazy-timer-fe/package-lock.json index 80d2ce0..333aa50 100644 --- a/lazy-timer-fe/package-lock.json +++ b/lazy-timer-fe/package-lock.json @@ -1,11 +1,11 @@ { - "name": "project_syncfusion_dashboard", + "name": "lazy-timer-fe", "version": "0.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "project_syncfusion_dashboard", + "name": "lazy-timer-fe", "version": "0.1.0", "dependencies": { "@syncfusion/ej2": "^19.4.48", @@ -18,6 +18,7 @@ "@syncfusion/ej2-react-popups": "^19.4.52", "@syncfusion/ej2-react-richtexteditor": "^19.4.50", "@syncfusion/ej2-react-schedule": "^19.4.50", + "axios": "^0.27.2", "react": "^17.0.2", "react-dom": "^17.0.2", "react-icons": "^4.3.1", @@ -4896,6 +4897,28 @@ "node": ">=4" } }, + "node_modules/axios": { + "version": "0.27.2", + "resolved": "https://registry.npmmirror.com/axios/-/axios-0.27.2.tgz", + "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "dependencies": { + "follow-redirects": "^1.14.9", + "form-data": "^4.0.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/axobject-query": { "version": "2.2.0", "resolved": "https://registry.npmmirror.com/axobject-query/-/axobject-query-2.2.0.tgz", @@ -19693,6 +19716,27 @@ "resolved": "https://registry.npmmirror.com/axe-core/-/axe-core-4.4.3.tgz", "integrity": "sha512-32+ub6kkdhhWick/UjvEwRchgoetXqTK14INLqbGm5U2TzBkBNF3nQtLYm8ovxSkQWArjEQvftCKryjZaATu3w==" }, + "axios": { + "version": "0.27.2", + "resolved": "https://registry.npmmirror.com/axios/-/axios-0.27.2.tgz", + "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "requires": { + "follow-redirects": "^1.14.9", + "form-data": "^4.0.0" + }, + "dependencies": { + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + } + } + }, "axobject-query": { "version": "2.2.0", "resolved": "https://registry.npmmirror.com/axobject-query/-/axobject-query-2.2.0.tgz", diff --git a/lazy-timer-fe/package.json b/lazy-timer-fe/package.json index 86d4120..846a097 100644 --- a/lazy-timer-fe/package.json +++ b/lazy-timer-fe/package.json @@ -13,6 +13,7 @@ "@syncfusion/ej2-react-popups": "^19.4.52", "@syncfusion/ej2-react-richtexteditor": "^19.4.50", "@syncfusion/ej2-react-schedule": "^19.4.50", + "axios": "^0.27.2", "react": "^17.0.2", "react-dom": "^17.0.2", "react-icons": "^4.3.1", diff --git a/lazy-timer-fe/src/data/dummy.js b/lazy-timer-fe/src/data/dummy.js index 01545d8..2d18150 100644 --- a/lazy-timer-fe/src/data/dummy.js +++ b/lazy-timer-fe/src/data/dummy.js @@ -1,11 +1,12 @@ import React from 'react'; import { AiOutlineCalendar, AiOutlineShoppingCart, AiOutlineAreaChart, AiOutlineBarChart, AiOutlineStock } from 'react-icons/ai'; import { FiShoppingBag, FiEdit, FiPieChart, FiBarChart, FiCreditCard, FiStar, FiShoppingCart } from 'react-icons/fi'; -import { BsKanban, BsBarChart, BsBoxSeam, BsCurrencyDollar, BsShield, BsChatLeft } from 'react-icons/bs'; +import { BsKanban, BsBarChart, BsCurrencyDollar, BsShield, BsChatLeft, BsFillLaptopFill } from 'react-icons/bs'; +import { FaSortAmountDown } from 'react-icons/fa' import { BiColorFill } from 'react-icons/bi'; import { IoMdContacts } from 'react-icons/io'; import { RiContactsLine, RiStockLine } from 'react-icons/ri'; -import { MdOutlineSupervisorAccount } from 'react-icons/md'; +import { MdWbSunny, MdBedtime } from 'react-icons/md'; import { HiOutlineRefresh } from 'react-icons/hi'; import { TiTick } from 'react-icons/ti'; import { GiLouvrePyramid } from 'react-icons/gi'; @@ -630,38 +631,38 @@ export const chatData = [ export const earningData = [ { - icon: , - amount: '39,354', + icon: , + amount: '这里填写时间', percentage: '-4%', - title: 'Customers', + title: '第一次屏幕使用', iconColor: '#03C9D7', iconBg: '#E5FAFB', pcColor: 'red-600', }, { - icon: , - amount: '4,396', + icon: , + amount: '这里填写时间', percentage: '+23%', - title: 'Products', + title: '最后一次屏幕使用', iconColor: 'rgb(255, 244, 229)', - iconBg: 'rgb(254, 201, 15)', - pcColor: 'green-600', + iconBg: 'rgb(0,0,0)', + pcColor: 'black-600', }, { - icon: , - amount: '423,39', + icon: , + amount: '这里填写时间', percentage: '+38%', - title: 'Sales', + title: '今日屏幕使用时间', iconColor: 'rgb(228, 106, 118)', iconBg: 'rgb(255, 244, 229)', pcColor: 'green-600', }, { - icon: , - amount: '39,354', + icon: , + amount: '这里填写时间', percentage: '-12%', - title: 'Refunds', + title: '总计', iconColor: 'rgb(0, 194, 146)', iconBg: 'rgb(235, 250, 242)', pcColor: 'red-600', diff --git a/lazy-timer-fe/src/pages/Ecommerce.jsx b/lazy-timer-fe/src/pages/Ecommerce.jsx index 5047964..909fa98 100644 --- a/lazy-timer-fe/src/pages/Ecommerce.jsx +++ b/lazy-timer-fe/src/pages/Ecommerce.jsx @@ -1,5 +1,6 @@ import React from 'react'; -import { BsCurrencyDollar } from 'react-icons/bs'; +import { BsFillLaptopFill } from 'react-icons/bs'; +import { AiFillCalendar } from 'react-icons/ai'; import { GoPrimitiveDot } from 'react-icons/go'; import { IoIosMore } from 'react-icons/io'; import { DropDownListComponent } from '@syncfusion/ej2-react-dropdowns'; @@ -25,8 +26,8 @@ const Ecommerce = () => {
-

Earnings

-

$63,448.78

+

日期

+

2022年9月5日

@@ -36,7 +37,7 @@ const Ecommerce = () => { style={{ backgroundColor: currentColor }} className="text-2xl opacity-0.9 text-white hover:drop-shadow-xl rounded-full p-4" > - + @@ -45,7 +46,7 @@ const Ecommerce = () => {
@@ -63,7 +64,7 @@ const Ecommerce = () => {

{item.amount} - {item.percentage} + {/* {item.percentage} */}

{item.title}