Skip to content

Commit

Permalink
feat: Update a lot of things
Browse files Browse the repository at this point in the history
  • Loading branch information
wormtql committed Mar 23, 2022
1 parent 5231e03 commit 8a8ff79
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 182 deletions.
7 changes: 7 additions & 0 deletions mona/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions mona/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ default = ["console_error_panic_hook"]
lto = true
opt-level = 3
strip = true
#codegen-units = 1

[dependencies]
mona_derive = { path = "../mona_derive" }
Expand All @@ -33,3 +34,4 @@ askama = "0.11"
askama_escape = "0.10.2"
strum = "0.23"
strum_macros = "0.23"
rustc-hash = "1.1.0"
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::cmp::{Ordering, Reverse};
use std::collections::{BinaryHeap, HashMap, HashSet};
use std::collections::hash_map::RandomState;
use std::collections::hash_map::{RandomState, DefaultHasher};
use std::hash::{Hash, Hasher};
use rustc_hash::FxHashSet;
use smallvec::SmallVec;
use crate::applications::optimize_artifacts::algorithm::SingleOptimizeAlgorithm;
use crate::applications::optimize_artifacts::algorithms::cutoff_heuristic::CutoffAlgorithmHeuristic;
use crate::applications::optimize_artifacts::inter::{ConstraintConfig, ConstraintSetMode, OptimizationResult};
Expand Down Expand Up @@ -71,7 +74,7 @@ fn check_attribute(attribute: &SimpleAttributeGraph2, constraint: &ConstraintCon
struct ResultRecorder<'a> {
result_heap: BinaryHeap<Reverse<OptimizationIntermediateResult>>,
result_count: usize,
result_set: HashSet<u64>,
result_set: FxHashSet<u64>,

artifact_config: ArtifactEffectConfig,
character: &'a Character<SimpleAttributeGraph2>,
Expand Down Expand Up @@ -109,7 +112,7 @@ impl<'a> ResultRecorder<'a> {
Self {
result_heap: BinaryHeap::with_capacity(result_count),
result_count,
result_set: HashSet::with_capacity(result_count),
result_set: FxHashSet::default(),

artifact_config,
character,
Expand All @@ -121,7 +124,7 @@ impl<'a> ResultRecorder<'a> {
}
}

fn calc_value(&self, arts: &Vec<&Artifact>) -> Option<f64> {
fn calc_value(&self, arts: &[&Artifact]) -> Option<f64> {
let artifact_list = ArtifactList {
artifacts: arts
};
Expand All @@ -142,15 +145,33 @@ impl<'a> ResultRecorder<'a> {
Some(value)
}

fn arts_to_u64(arts_id: &[u64; 5]) -> u64 {
arts_id.iter().fold(0_u64, |acc, id| acc * 2000 + id)
// arts id are sorted by slots
fn arts_to_u64(arts_id: &[u64]) -> u64 {
let mut s = DefaultHasher::new();
for &id in arts_id.iter() {
id.hash(&mut s);
}
// arts_id.iter().fold(0_u64, |acc, id| acc * 2000 + id)
s.finish()
}

fn push_result(&mut self, arts: &Vec<&Artifact>, value: f64) {
fn push_result(&mut self, arts: &[&Artifact], value: f64) {
// utils::log!("push_result {}", value);
let mut arts = arts.clone();
arts.sort_by_key(|art| art.slot as usize);
let arts_id: [u64; 5] = arts.iter().map(|art| art.id).collect::<Vec<_>>().try_into().unwrap();

let mut slot_ids: SmallVec<[(usize, u64); 5]> = SmallVec::new();
for art in arts.iter() {
slot_ids.push((art.slot as usize, art.id));
}
slot_ids.sort_by_key(|x| x.0);

let mut arts_id: [u64; 5] = [0; 5];
for (index, (_, id)) in slot_ids.iter().enumerate() {
arts_id[index] = *id;
}

// arts.sort_by_key(|art| art.slot as usize);
// let arts_id: [u64; 5] = arts.iter().map(|art| art.id).collect::<Vec<_>>().try_into().unwrap();
let hash = Self::arts_to_u64(&arts_id);
if self.result_set.contains(&hash) {
return;
Expand All @@ -168,7 +189,7 @@ impl<'a> ResultRecorder<'a> {
self.result_set.insert(hash);
}

fn check_hope(&self, arts: &Vec<&Artifact>) -> (bool, f64) {
fn check_hope(&self, arts: &[&Artifact]) -> (bool, f64) {
if let Some(value) = self.calc_value(&arts) {
// utils::log!("check_hope {}", value);
(value > self.result_heap.peek().map_or(0., |r| r.0.value), value)
Expand All @@ -177,12 +198,12 @@ impl<'a> ResultRecorder<'a> {
}
}

fn check_hope_option(&self, arts: &Vec<Option<&Artifact>>) -> bool {
fn check_hope_option(&self, arts: &[Option<&Artifact>]) -> bool {
// utils::log!("check_hope_option {}", arts.len());
if arts.iter().any(|op| op.is_none()) {
return false;
}
let arts: Vec<_> = arts.iter().map(|op| op.unwrap()).collect();
let arts: SmallVec<[&Artifact; 5]> = arts.iter().map(|op| op.unwrap()).collect();
self.check_hope(&arts).0
}
}
Expand Down
4 changes: 2 additions & 2 deletions mona/src/bin/bench_cutoff2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn create_target_function(character: &Character<SimpleAttributeGraph2>, weapon:

fn generate_artifacts() -> Vec<Artifact> {
let mut artifacts = vec![];
for _ in 0..25 {
for _ in 0..50 {
artifacts.push(Artifact::new_random(ArtifactSlotName::Flower));
artifacts.push(Artifact::new_random(ArtifactSlotName::Feather));
artifacts.push(Artifact::new_random(ArtifactSlotName::Sand));
Expand Down Expand Up @@ -102,7 +102,7 @@ fn main() {
&enemy,
&[],
&constraint,
100
5
);

println!("{:?}", results);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genshin_artifacts",
"version": "4.15.0",
"version": "5.0.0",
"private": true,
"scripts": {
"serve": "cross-env MONA_TITLE=莫娜占卜铺 MONA_NEED_BEIAN=false MONA_NEED_MIGRATE=false MONA_ROUTE_MODE=hash vue-cli-service serve",
Expand Down
129 changes: 105 additions & 24 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,9 @@
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>莫娜占卜铺</title>

<!-- <link rel="stylesheet" href="https://unpkg.com/element-ui@2.15.1/lib/theme-chalk/index.css"> -->
<!-- <link rel="stylesheet" href="https://unpkg.com/element-ui@2.15.1/lib/theme-chalk/display.css"> -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/element-ui@2.15.6/lib/theme-chalk/index.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/element-ui@2.15.6/lib/theme-chalk/display.css">
<link rel="stylesheet" href="https://unpkg.zhimg.com/element-ui@2.15.6/lib/theme-chalk/index.css">
<link rel="stylesheet" href="https://unpkg.zhimg.com/element-ui@2.15.6/lib/theme-chalk/display.css">

<!-- <script src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
<script src="https://cdn.bootcss.com/vue-router/3.4.8/vue-router.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/vuex/3.5.1/vuex.min.js"></script>
<script src="https://unpkg.com/element-ui@2.15.1/lib/index.js"></script> -->
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-router@3.4.8/dist/vue-router.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuex@3.5.1/dist/vuex.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/element-ui@2.15.6/lib/index.js"></script>

<script src="https://cdn.jsdelivr.net/npm/@vue/composition-api@1.0.0-rc.3"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts@5.3.0"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.0.0-rc.4"></script>

<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.5.3"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/vue-katex@0.5.0/dist/vue-katex.cjs.min.js"></script> -->
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.13.0/dist/katex.min.css" integrity="sha384-t5CR+zwDAROtph0PXGte6ia8heboACF9R5l/DiY+WZ3P2lxNgvJkQk5n7GPvLMYw" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.13.0/dist/katex.min.js" integrity="sha384-FaFLTlohFghEIZkw6VGwmf9ISTubWAVYW8tG8+w2LAIftJEULZABrF9PPFv+tVkH" crossorigin="anonymous"></script> -->

<style>
.loading {
height: 100vh;
Expand All @@ -56,10 +36,111 @@
<strong>好家伙,这年头还有不开启javascript的人吗</strong>
</noscript>
<div id="app">
<div class="loading">
<span>莫娜正在仰望星空,请稍安勿躁(狗头)</span>
<div class="loading"
style="display: flex; flex-direction: column; align-items: center"
>
<div class="lds-roller"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>
<p style="margin-top: 12px">莫娜正在仰望星空,请稍安勿躁(狗头)</p>
</div>
</div>

<style>
.lds-roller {
display: inline-block;
position: relative;
width: 40px;
height: 40px;
}
.lds-roller div {
animation: lds-roller 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
transform-origin: 20px 20px;
}
.lds-roller div:after {
content: " ";
display: block;
position: absolute;
width: 4px;
height: 4px;
border-radius: 50%;
background: #564884;
margin: -4px 0 0 -4px;
}
.lds-roller div:nth-child(1) {
animation-delay: -0.036s;
}
.lds-roller div:nth-child(1):after {
top: 30px;
left: 30px;
}
.lds-roller div:nth-child(2) {
animation-delay: -0.072s;
}
.lds-roller div:nth-child(2):after {
top: 34px;
left: 28px;
}
.lds-roller div:nth-child(3) {
animation-delay: -0.108s;
}
.lds-roller div:nth-child(3):after {
top: 35px;
left: 24px;
}
.lds-roller div:nth-child(4) {
animation-delay: -0.144s;
}
.lds-roller div:nth-child(4):after {
top: 36px;
left: 20px;
}
.lds-roller div:nth-child(5) {
animation-delay: -0.18s;
}
.lds-roller div:nth-child(5):after {
top: 35px;
left: 16px;
}
.lds-roller div:nth-child(6) {
animation-delay: -0.216s;
}
.lds-roller div:nth-child(6):after {
top: 34px;
left: 12px;
}
.lds-roller div:nth-child(7) {
animation-delay: -0.252s;
}
.lds-roller div:nth-child(7):after {
top: 31px;
left: 8px;
}
.lds-roller div:nth-child(8) {
animation-delay: -0.288s;
}
.lds-roller div:nth-child(8):after {
top: 28px;
left: 6px;
}
@keyframes lds-roller {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>

<script src="https://unpkg.zhimg.com/vue@2.6.11/dist/vue.min.js"></script>
<script src="https://unpkg.zhimg.com/vue-router@3.4.8/dist/vue-router.min.js"></script>
<script src="https://unpkg.zhimg.com/vuex@3.5.1/dist/vuex.min.js"></script>
<script src="https://unpkg.zhimg.com/element-ui@2.15.6/lib/index.js"></script>

<script src="https://unpkg.com/@vue/composition-api@1.0.0-rc.3"></script>
<script src="https://unpkg.com/echarts@5.3.0"></script>
<script src="https://unpkg.zhimg.com/vue-echarts@6.0.0-rc.4"></script>

<script src="https://unpkg.com/fuse.js@6.5.3"></script>
<!-- built files will be auto injected -->
</body>
</html>
10 changes: 10 additions & 0 deletions src/pages/MainPage/MainPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<router-view v-if="!$route.meta.keepAlive" class="router-view"></router-view>

<beian v-if="needBeian"></beian>
<!-- <p>123</p>-->
</el-main>
</el-container>
</el-container>
Expand Down Expand Up @@ -83,6 +84,15 @@ export default {
height: 100vh;
}
.main::-webkit-scrollbar {
display: none;
}
.main {
-ms-overflow-style: none;
scrollbar-width: none;
}
/*.main {*/
/* overflow-x: visible;*/
/*}*/
Expand Down
1 change: 1 addition & 0 deletions src/pages/NewArtifactPlanPage/NewArtifactPlanPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@
></el-input-number>
<value-display
:value="optimizationResults[optimizationResultIndex - 1].ratio"
:extra="optimizationResults[optimizationResultIndex - 1].value.toFixed(1)"
style="margin-top: 12px"
></value-display>
</div>
Expand Down
11 changes: 9 additions & 2 deletions src/pages/NewArtifactPlanPage/ValueDisplay.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<template>
<div class="root">
<div class="back" :style="styleForBack"></div>
<span class="display">{{ (value * 100).toFixed(1) }}</span>
<span class="display">{{ (value * 100).toFixed(1) }}
<span v-if="extra">/ {{ extra }}</span>
</span>
</div>
</template>

<script>
export default {
name: "ValueDisplay",
props: ["value"],
props: {
"value": {},
"extra": {
default: ""
}
},
computed: {
styleForBack() {
return {
Expand Down
14 changes: 7 additions & 7 deletions src/pages/TeamOptimizationPage/TeamOptimizationPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@
</div>

<div class="result-item-buttons">
<el-button
icon="el-icon-plus"
circle
size="mini"
type="text"
title="存为套装"
></el-button>
<!-- <el-button-->
<!-- icon="el-icon-plus"-->
<!-- circle-->
<!-- size="mini"-->
<!-- type="text"-->
<!-- title="存为套装"-->
<!-- ></el-button>-->
</div>
</div>
<div class="result-item-content">
Expand Down
Loading

0 comments on commit 8a8ff79

Please sign in to comment.