Skip to content

Commit

Permalink
Perf: calculate gpa of selected score info
Browse files Browse the repository at this point in the history
  • Loading branch information
PeiPei233 committed Apr 10, 2024
1 parent 7bd1c34 commit 1d87336
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"package": {
"productName": "zju-learning-assistant",
"version": "0.3.3"
"version": "0.3.4"
},
"tauri": {
"allowlist": {
Expand Down
6 changes: 2 additions & 4 deletions src/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export default function Home({ setIsLogin, setAutoLoginUsername, setAutoLoginPas
if (item.end_time) {
const key = `${item.course_id}-${item.id}-${item.end_time}`
const diffTime = dayjs(item.end_time).diff(dayjs(), 'minute')
if (!notifiedTodo.current[key] && diffTime <= 60 && diffTime > 0 ) {
if (!notifiedTodo.current[key] && diffTime <= 60 && diffTime > 0) {
let permissionGranted = await isPermissionGranted();
if (!permissionGranted) {
const permission = await requestPermission();
Expand Down Expand Up @@ -339,7 +339,6 @@ export default function Home({ setIsLogin, setAutoLoginUsername, setAutoLoginPas
}
}


const updatePath = () => {
dialog.open({
directory: true,
Expand All @@ -366,7 +365,6 @@ export default function Home({ setIsLogin, setAutoLoginUsername, setAutoLoginPas
})
}


const updateUploadList = () => {
let courses = courseList.filter((item) => selectedCourseKeys.includes(item.id))
// console.log(courses)
Expand Down Expand Up @@ -567,7 +565,7 @@ export default function Home({ setIsLogin, setAutoLoginUsername, setAutoLoginPas
}}
/>
</Tooltip>
<Tooltip title='全部删除'>
<Tooltip title='清空下载列表'>
<Button
type='text'
icon={<DeleteOutlined />}
Expand Down
14 changes: 2 additions & 12 deletions src/Learning.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,6 @@ export default function Learning({
const filterOption = (input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase());

const onSelectChange = (newSelectedRowKeys) => {
// console.log('selectedRowKeys changed: ', newSelectedRowKeys);
setSelectedCourseKeys(newSelectedRowKeys)
};

const onUploadSelectChange = (newSelectedRowKeys) => {
// console.log('selectedRowKeys changed: ', newSelectedRowKeys);
setSelectedUploadKeys(newSelectedRowKeys)
}

const uploadColumns = [
{
title: '课程名称',
Expand Down Expand Up @@ -260,7 +250,7 @@ export default function Learning({
<SearchTable
rowSelection={{
selectedRowKeys: selectedCourseKeys,
onChange: onSelectChange,
onChange: setSelectedCourseKeys,
}}
columns={courseColumns}
dataSource={selectedCourses}
Expand All @@ -277,7 +267,7 @@ export default function Learning({
<SearchTable
rowSelection={{
selectedRowKeys: selectedUploadKeys,
onChange: onUploadSelectChange,
onChange: setSelectedUploadKeys,
}}
rowKey='reference_id'
columns={uploadColumns}
Expand Down
37 changes: 31 additions & 6 deletions src/Score.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from 'react'
import { useState, useEffect } from 'react'
import { Button, Card, App, Typography, Input, Switch, Tooltip } from 'antd';
import { SyncOutlined } from '@ant-design/icons';
import SearchTable from './SearchTable'
Expand All @@ -22,6 +22,10 @@ export default function Score({

const { message, modal, notification } = App.useApp()

const [selectedXkkh, setSelectedXkkh] = useState([])
const [selectedTotalGp, setSelectedTotalGp] = useState(0)
const [selectedTotalCredit, setSelectedTotalCredit] = useState(0)

useEffect(() => {
handleSync()
}, [])
Expand Down Expand Up @@ -82,17 +86,31 @@ export default function Score({
},
]

const onSelectChange = (selectedRowKeys, selectedRows) => {
setSelectedXkkh(selectedRowKeys)
let totalGp = 0
let totalCredit = 0
selectedRows.forEach(row => {
if (row.cj !== '合格' && row.cj !== '不合格' && row.cj !== '弃修') {
totalGp += parseFloat(row.jd) * parseFloat(row.xf)
totalCredit += parseFloat(row.xf)
}
})
setSelectedTotalGp(totalGp)
setSelectedTotalCredit(totalCredit)
}

return (
<div style={{ margin: 20 }}>
<Card bodyStyle={{ padding: 15 }}>
<Card styles={{ body: { padding: 15 } }}>
<div style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}} >
<div style={{ display: 'flex', alignItems: 'center', flexDirection: 'row' }}>
<Text style={{ minWidth: 115 }}>自动同步并提醒:</Text>
<Tooltip title={notify ? '成绩推送已开启,将自动同步最新成绩并在成绩更新时提醒' : '成绩推送已关闭'}>
<Tooltip title={notify ? '成绩推送已开启,将自动同步最新成绩并在成绩更新时提醒' : '成绩推送已关闭,开启后将自动同步最新成绩并在成绩更新时提醒'}>
<Switch loading={loading} checked={notify} onChange={handleSwitch} />
</Tooltip>
</div>
Expand All @@ -102,16 +120,23 @@ export default function Score({
</div>
</Card>
<SearchTable
rowSelection={{
selectedRowKeys: selectedXkkh,
onChange: onSelectChange,
}}
columns={columns}
dataSource={score}
rowKey='xkkh'
pagination={false}
scroll={{ y: 'calc(100vh - 255px)' }}
size='small'
bordered
footer={() => `最后同步时间:${lastSync ? lastSync : '未同步'},共 ${score.length} 条记录,总绩点 ${(
totalCredit === 0 ? 0 : totalGp / totalCredit
).toFixed(2)},总学分 ${totalCredit.toFixed(2)}`}
footer={() => selectedXkkh.length ? `最后同步时间:${lastSync ? lastSync : '未同步'},已选 ${selectedXkkh.length} 条记录,已选总绩点 ${(
selectedTotalCredit === 0 ? 0 : selectedTotalGp / selectedTotalCredit
).toFixed(2)},已选总学分 ${selectedTotalCredit.toFixed(2)}` :
`最后同步时间:${lastSync ? lastSync : '未同步'},共 ${score.length} 条记录,总绩点 ${(
totalCredit === 0 ? 0 : totalGp / totalCredit
).toFixed(2)},总学分 ${totalCredit.toFixed(2)}`}
style={{ marginTop: 20 }}
loading={loading}
/>
Expand Down
4 changes: 1 addition & 3 deletions src/SearchTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Button, Table, Input, Space } from 'antd';
import { SearchOutlined } from '@ant-design/icons';
import Highlighter from 'react-highlight-words';

const SearchTable = ({ columns, dataSource, loading, pagination, scroll, size, bordered, footer, title, rowSelection, rowKey, onSelectChange, selectedRowKeys, style }) => {
const SearchTable = ({ columns, dataSource, loading, pagination, scroll, size, bordered, footer, title, rowSelection, rowKey, style }) => {
const [searchText, setSearchText] = useState('')
const [searchedColumn, setSearchedColumn] = useState('')
const searchInput = useRef(null)
Expand Down Expand Up @@ -134,8 +134,6 @@ const SearchTable = ({ columns, dataSource, loading, pagination, scroll, size, b
bordered={bordered}
footer={footer}
title={title}
onSelectChange={onSelectChange}
selectedRowKeys={selectedRowKeys}
style={style}
/>
}
Expand Down
14 changes: 7 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ export function convertUrlsToMarkdown(text: string): string {
let placeholders: string[] = [];
let currentIndex = 0;
let newText = text.replace(markdownLinkRegex, (match) => {
placeholders.push(match);
return `<<${currentIndex++}>>`;
placeholders.push(match);
return `<<${currentIndex++}>>`;
});

const urlRegex = /http[s]?:\/\/[^\s\[\]()]+/g;
newText = newText.replace(urlRegex, (match) => `[${match}](${match})`);

placeholders.forEach((placeholder, index) => {
newText = newText.replace(`<<${index}>>`, placeholder);
newText = newText.replace(`<<${index}>>`, placeholder);
});

return newText;
}
}

0 comments on commit 1d87336

Please sign in to comment.