Skip to content

Commit

Permalink
refactor: fix @yb6b 's result page
Browse files Browse the repository at this point in the history
  • Loading branch information
nopdan committed Mar 12, 2024
1 parent b209a1f commit 5ef3c9b
Show file tree
Hide file tree
Showing 11 changed files with 557 additions and 201 deletions.
Binary file modified frontend/bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions frontend/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ declare module "@vue/runtime-core" {
MultiResult: (typeof import("./src/components/MultiResult.vue"))["default"];
NButton: (typeof import("naive-ui"))["NButton"];
NCard: (typeof import("naive-ui"))["NCard"];
NDescriptions: (typeof import("naive-ui"))["NDescriptions"];
NDescriptionsItem: (typeof import("naive-ui"))["NDescriptionsItem"];
NDivider: (typeof import("naive-ui"))["NDivider"];
NDrawer: (typeof import("naive-ui"))["NDrawer"];
NDrawerContent: (typeof import("naive-ui"))["NDrawerContent"];
Expand Down
22 changes: 21 additions & 1 deletion frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Main from "./components/Main.vue";
<template>
<n-message-provider>
<div class="content">
<div class="header">昙花赛码器</div>
<n-card>
<Main />
</n-card>
Expand All @@ -13,7 +14,26 @@ import Main from "./components/Main.vue";
</template>
<style>
.content {
margin: 1em auto;
margin: auto;
max-width: 800px;
min-height: 90vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-family: -apple-system, "Noto Sans", "Helvetica Neue", Helvetica, "Nimbus Sans L", Arial, "Liberation Sans",
"PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", "Source Han Sans CN", "Microsoft YaHei",
"Wenquanyi Micro Hei", "WenQuanYi Zen Hei", "ST Heiti", SimHei, "WenQuanYi Zen Hei Sharp", sans-serif;
}
.header {
background-image: linear-gradient(to right, orange, rgb(197, 4, 245));
background-clip: text;
color: transparent;
font-size: xx-large;
font-weight: bold;
padding: 1em;
font-family: Baskerville, Georgia, "Liberation Serif", "Kaiti SC", STKaiti, "AR PL UKai CN", "AR PL UKai HK",
"AR PL UKai TW", "AR PL UKai TW MBE", "AR PL KaitiM GB", KaiTi, KaiTi_GB2312, DFKai-SB, "TW\-Kai", serif;
}
</style>
173 changes: 173 additions & 0 deletions frontend/src/components/Data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Generated by https://quicktype.io

import { OldData } from "./OldData";

export interface Data {
Info: Info;
Commit: Char;
Expand Down Expand Up @@ -67,3 +69,174 @@ export interface Pair {
SameHand: number;
DiffHand: number;
}

export class DataUtils {
data: Data;
constructor(data: Data) {
this.data = data;
}
_commitRate(count: number): number {
return count / this.data.Commit.Count;
}
_charRate(count: number): number {
return count / this.data.Char.Count;
}
_keyRate(count: number): number {
return count / this.data.Keys.Count;
}
_pairRate(count: number): number {
return count / this.data.Pair.Count;
}

commitRate(count: number, fixed = 2): string {
return (this._commitRate(count) * 100).toFixed(fixed) + "%";
}

charRate(count: number, fixed = 2): string {
return (this._charRate(count) * 100).toFixed(fixed) + "%";
}

keyRate(count: number, fixed = 2): string {
return (this._keyRate(count) * 100).toFixed(fixed) + "%";
}

pairRate(count: number, fixed = 2): string {
return (this._pairRate(count) * 100).toFixed(fixed) + "%";
}
}

export function New2Old(_new: Data): OldData {
const util = new DataUtils(_new);
const _old: OldData = {
TextName: _new.Info.TextName,
TextLen: _new.Info.TextLen,
DictName: _new.Info.DictName,
DictLen: _new.Info.DictLen,
Single: _new.Info.Single,
Basic: {
NotHan: _new.Han.NotHan,
NotHans: _new.Han.NotHans,
NotHanCount: _new.Han.NotHanCount,
Lack: _new.Han.Lack,
Lacks: _new.Han.Lacks,
LackCount: _new.Han.LackCount,
Commits: _new.Commit.Count,
},
Words: {
Commits: {
Count: _new.Commit.Word,
Rate: util._commitRate(_new.Commit.Word),
},
Chars: {
Count: _new.Char.Word,
Rate: util._charRate(_new.Char.Word),
},
Dist: _new.Dist.WordLen,
},
Collision: {
Commits: {
Count: _new.Commit.Collision,
Rate: util._commitRate(_new.Commit.Collision),
},
Chars: {
Count: _new.Char.Collision,
Rate: util._charRate(_new.Char.Collision),
},
Dist: _new.Dist.Collision,
},
CodeLen: {
Total: _new.Keys.Count,
PerChar: _new.Keys.CodeLen,
Dist: _new.Dist.CodeLen,
},
Keys: {},
Combs: {
Count: _new.Pair.Count,
Equivalent: util._pairRate(_new.Pair.Equivalent),
DoubleHit: {
Count: _new.Pair.DoubleHit,
Rate: util._pairRate(_new.Pair.DoubleHit),
},
TribleHit: {
Count: _new.Pair.TribleHit,
Rate: util._pairRate(_new.Pair.TribleHit),
},
SingleSpan: {
Count: _new.Pair.SingleSpan,
Rate: util._pairRate(_new.Pair.SingleSpan),
},
MultiSpan: {
Count: _new.Pair.MultiSpan,
Rate: util._pairRate(_new.Pair.MultiSpan),
},
LongFingersDisturb: {
Count: _new.Pair.Staggered,
Rate: util._pairRate(_new.Pair.Staggered),
},
LittleFingersDisturb: {
Count: _new.Pair.Disturb,
Rate: util._pairRate(_new.Pair.Disturb),
},
},
Fingers: {
Dist: [],
Same: {
Count: _new.Pair.SameFinger,
Rate: util._pairRate(_new.Pair.SameFinger),
},
Diff: {
Count: _new.Pair.DiffFinger,
Rate: util._pairRate(_new.Pair.DiffFinger),
},
},
Hands: {
Left: {
Count: _new.Keys.LeftHand,
Rate: util._keyRate(_new.Keys.LeftHand),
},
Right: {
Count: _new.Keys.RightHand,
Rate: util._keyRate(_new.Keys.RightHand),
},
Same: {
Count: _new.Pair.SameHand,
Rate: util._pairRate(_new.Pair.SameHand),
},
Diff: {
Count: _new.Pair.DiffHand,
Rate: util._pairRate(_new.Pair.DiffHand),
},
LeftToLeft: {
Count: _new.Pair.LeftToLeft,
Rate: util._pairRate(_new.Pair.LeftToLeft),
},
LeftToRight: {
Count: _new.Pair.LeftToRight,
Rate: util._pairRate(_new.Pair.LeftToRight),
},
RightToLeft: {
Count: _new.Pair.RightToLeft,
Rate: util._pairRate(_new.Pair.RightToLeft),
},
RightToRight: {
Count: _new.Pair.RightToRight,
Rate: util._pairRate(_new.Pair.RightToRight),
},
},
};

for (const key in _new.Dist.Key) {
_old.Keys[key] = {
Count: _new.Dist.Key[key],
Rate: util._keyRate(_new.Dist.Key[key]),
};
}

for (const key in _new.Dist.Finger) {
_old.Fingers.Dist.push({
Count: _new.Dist.Finger[key],
Rate: util._keyRate(_new.Dist.Finger[key]),
});
}
return _old;
}
Loading

0 comments on commit 5ef3c9b

Please sign in to comment.