Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into frzyc/go-next
Browse files Browse the repository at this point in the history
  • Loading branch information
frzyc committed Dec 18, 2023
2 parents 0d445ab + a95caa0 commit ed76079
Show file tree
Hide file tree
Showing 141 changed files with 759 additions and 350 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy-go-pando-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ on:
- 'apps/sr-frontend-e2e/**'
- 'libs/sr-assets/**'
- 'libs/sr-consts/**'
- 'libs/sr-db/**'
- 'libs/sr-dm/**'
- 'libs/sr-formula/**'
- 'libs/sr-srod/**'
- 'libs/sr-stats/**'
types: [opened, reopened, synchronize, labeled]

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deploy-go-wr-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ on:
- 'apps/sr-frontend-e2e/**'
- 'libs/sr-assets/**'
- 'libs/sr-consts/**'
- 'libs/sr-db/**'
- 'libs/sr-dm/**'
- 'libs/sr-formula/**'
- 'libs/sr-srod/**'
- 'libs/sr-stats/**'
- 'libs/pando/**'
- 'libs/gi-formula/**'
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/deploy-sro-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ on:
- 'apps/gi-frontend-e2e/**'
- 'apps/frontend/**'
- 'apps/frontend-e2e/**'
- 'libs/consts/**'
- 'libs/dm/**'
- 'libs/gi-art-scanner/**'
- 'libs/gi-assets/**'
- 'libs/gi-consts/**'
- 'libs/gi-dm-localization/**'
- 'libs/gi-formula/**'
- 'libs/gi-formula-ui/**'
- 'libs/gi-good/**'
- 'libs/gi-localization/**'
- 'libs/gi-stats/**'
- 'libs/gi-svgicons/**'
- 'libs/gi-util/**'
- 'libs/gi-ui/**'
- 'libs/gi-util/**'
- 'libs/silly-wisher/**'
- 'libs/silly-wisher-names/**'
types: [opened, reopened, synchronize, labeled]

jobs:
Expand Down
25 changes: 11 additions & 14 deletions apps/frontend/src/app/Data/Artifacts/Artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export default class Artifact {
)
)

//ARTIFACT IN GENERAL
/**
* @deprecate
*/
static getArtifactEfficiency(
artifact: ICachedArtifact,
filter: Set<SubstatKey>
Expand All @@ -59,19 +61,14 @@ export default class Artifact {
filter.size -
matchedSlotCount -
(filter.has(artifact.mainStatKey as any) ? 1 : 0)
let maxEfficiency
if (emptySlotCount && unusedFilterCount)
maxEfficiency =
currentEfficiency +
Artifact.maxSubstatRollEfficiency[rarity] * rollsRemaining
// Rolls into good empty slot
else if (matchedSlotCount)
maxEfficiency =
currentEfficiency +
Artifact.maxSubstatRollEfficiency[rarity] *
(rollsRemaining - emptySlotCount)
// Rolls into existing matched slot
else maxEfficiency = currentEfficiency // No possible roll

let maxEfficiency = currentEfficiency
const maxRollEff = Artifact.maxSubstatRollEfficiency[rarity]
// Rolls into good empty slots, assuming max-level artifacts have no empty slots
maxEfficiency += maxRollEff * Math.min(emptySlotCount, unusedFilterCount)
// Rolls into an existing good slot
if (matchedSlotCount || (emptySlotCount && unusedFilterCount))
maxEfficiency += maxRollEff * (rollsRemaining - emptySlotCount)

return { currentEfficiency, maxEfficiency }
}
Expand Down
12 changes: 6 additions & 6 deletions apps/frontend/src/app/PageArtifact/ArtifactEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import SubstatInput from './ArtifactEditor/Components/SubstatInput'
import UploadExplainationModal from './ArtifactEditor/Components/UploadExplainationModal'
import { textsFromImage } from './ScanningUtil'
import { LocationAutocomplete } from '../Components/Character/LocationAutocomplete'
import { shouldShowDevComponents } from '../Util/Util'

const allSubstatFilter = new Set(allSubstatKeys)
type ResetMessage = { type: 'reset' }
Expand Down Expand Up @@ -593,12 +594,11 @@ export default function ArtifactEditor({
</Button>
</label>
</Grid>
{process.env.NODE_ENV === 'development' &&
debugImgs && (
<Grid item>
<DebugModal imgs={debugImgs} />
</Grid>
)}
{shouldShowDevComponents && debugImgs && (
<Grid item>
<DebugModal imgs={debugImgs} />
</Grid>
)}
<Grid item>
<Button
color="info"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function CharacterTalentPane() {
<DropdownButton
fullWidth
title={`Constellation Lv. ${constellation}`}
color={'success'}
color="primary"
sx={{ borderRadius: 0 }}
>
{range(0, maxConstellationCount).map((i) => (
Expand Down
32 changes: 32 additions & 0 deletions libs/gi-art-scanner/src/lib/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,38 @@ export const goldenTitleLighterColor: Color = {
b: 50,
}

/**
* "purple" title
* light: a056e0 rgb(160, 86, 224)
* dark: 7943a7 rgb(121, 67, 167)
*/
export const purpleTitleDarkerColor: Color = {
r: 121,
g: 67,
b: 167,
}
export const purpleTitleLighterColor: Color = {
r: 160,
g: 86,
b: 224,
}

/**
* "blue" title
* light: 517fcc rgb(81, 127, 204)
* dark: 3e6095 rgb(62, 96, 149)
*/
export const blueTitleDarkerColor: Color = {
r: 62,
g: 96,
b: 149,
}
export const blueTitleLighterColor: Color = {
r: 81,
g: 127,
b: 204,
}

// The "baige" background of artifact card, ebe4d8 rgb(235, 228, 216)
export const cardWhite: Color = {
r: 235,
Expand Down
31 changes: 22 additions & 9 deletions libs/gi-art-scanner/src/lib/findBestArtifact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
import {
allArtifactRarityKeys,
allArtifactSlotKeys,
artSlotsData,
artSlotMainKeys,
} from '@genshin-optimizer/consts'
import type { IArtifact, ISubstat } from '@genshin-optimizer/gi-good'
import { allStats } from '@genshin-optimizer/gi-stats'
Expand Down Expand Up @@ -54,9 +54,9 @@ export function findBestArtifact(
if (location)
texts.location = detectedText(location, 'Location', (value) => value)

const relevantSetKey = [
...new Set<ArtifactSetKey>([...textSetKeys, 'EmblemOfSeveredFate']),
]
const relevantSetKey: ArtifactSetKey[] = textSetKeys.size
? [...textSetKeys]
: ['EmblemOfSeveredFate']

let bestScore = -1,
bestArtifacts: IArtifact[] = [
Expand Down Expand Up @@ -101,14 +101,16 @@ export function findBestArtifact(

// Test all *probable* combinations
for (const slotKey of allArtifactSlotKeys) {
for (const mainStatKey of artSlotsData[slotKey].stats) {
for (const mainStatKey of artSlotMainKeys[slotKey]) {
const mainStatUnit = unit(mainStatKey)
const mainStatFixed = mainStatUnit === '%' ? 1 : 0
const mainStatOffset = mainStatUnit === '%' ? 0.1 : 1
const mainStatScore =
(slotKeys.has(slotKey) ? 1 : 0) +
(mainStatKeys.has(mainStatKey) ? 1 : 0)
const relevantMainStatValues = mainStatValues
.filter((value) => value.unit !== '%' || unit(mainStatKey) === '%') // Ignore "%" text if key isn't "%"
.map((value) => value.mainStatValue)

for (const [rarityString, rarityIndividualScore] of Object.entries(
rarityRates
)) {
Expand All @@ -124,11 +126,17 @@ export function findBestArtifact(
const values = getMainStatDisplayValues(rarity, mainStatKey)
const level = Math.max(
0,
values.findIndex((level) => level >= minimumMainStatValue)
values.findIndex(
(level) => level + mainStatOffset >= minimumMainStatValue
)
)
const mainStatVal = values[level]
const mainStatValScore =
rarityScore + (mainStatVal === minimumMainStatValue ? 1 : 0)
rarityScore +
(mainStatVal.toFixed(mainStatFixed) ===
minimumMainStatValue.toFixed(mainStatFixed)
? 1
: 0)

for (const setKey of setKeys) {
const score = mainStatValScore + (textSetKeys.has(setKey) ? 1 : 0)
Expand Down Expand Up @@ -314,8 +322,13 @@ export function findBestArtifact(
{unit(result.mainStatKey)}
</>
)
const toFixed = unit(result.mainStatKey) === '%' ? 1 : 0
if (
mainStatValues.find((value) => value.mainStatValue === resultMainStatVal)
mainStatValues.find(
(value) =>
value.mainStatValue.toFixed(toFixed) ===
resultMainStatVal.toFixed(toFixed)
)
) {
if (mainStatKeys.has(result.mainStatKey)) {
texts.level = detectedText(result.level, 'Level', (value) => '+' + value)
Expand Down
89 changes: 44 additions & 45 deletions libs/gi-art-scanner/src/lib/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,61 @@ import {
allSubstatKeys,
} from '@genshin-optimizer/consts'
import type { ISubstat } from '@genshin-optimizer/gi-good'
import { hammingDistance, unit } from '@genshin-optimizer/util'
import { levenshteinDistance, unit } from '@genshin-optimizer/util'
import { artSlotNames, statMap } from './enStringMap'

/** small utility function used by most string parsing functions below */
export type KeyDist<T extends string> = [T, number]
export function getBestKeyDist<T extends string>(hams: Array<KeyDist<T>>) {
const minHam = Math.min(...hams.map(([, ham]) => ham))
const keys = hams.filter(([, ham]) => ham === minHam).map(([key]) => key)
return new Set(keys)
}

export function parseSetKeys(texts: string[]): Set<ArtifactSetKey> {
const results = new Set<ArtifactSetKey>([])
const kdist: Array<KeyDist<ArtifactSetKey>> = []
for (const text of texts)
for (const key of allArtifactSetKeys)
if (
hammingDistance(
kdist.push([
key,
levenshteinDistance(
text.replace(/\W/g, ''),
key //TODO: use the translated set name?
) <= 2
)
results.add(key)
return results
),
])
return getBestKeyDist(kdist)
}

export function parseSlotKeys(texts: string[]): Set<ArtifactSlotKey> {
const results = new Set<ArtifactSlotKey>()
const kdist: Array<KeyDist<ArtifactSlotKey>> = []
for (const text of texts)
for (const key of allArtifactSlotKeys)
if (
hammingDistance(
kdist.push([
key,
levenshteinDistance(
text.replace(/\W/g, ''),
artSlotNames[key].replace(/\W/g, '')
) <= 2
)
results.add(key)
return results
),
])
return getBestKeyDist(kdist)
}
export function parseMainStatKeys(texts: string[]): Set<MainStatKey> {
const results = new Set<MainStatKey>([])
const kdist: Array<KeyDist<MainStatKey>> = []
for (const text of texts)
for (const key of allMainStatKeys) {
if (text.toLowerCase().includes(statMap[key]?.toLowerCase() ?? ''))
results.add(key)
//use fuzzy compare on the ... Bonus texts. heal_ is included.
if (
key.includes('_bonu') &&
hammingDistance(
text.replace(/\W/g, ''),
(statMap[key] ?? '').replace(/\W/g, '')
) <= 1
)
results.add(key)
const statStr = statMap[key]?.toLowerCase()
if (statStr.length <= 3) {
if (text.toLowerCase().includes(statStr ?? '')) kdist.push([key, 0])
} else
kdist.push([
key,
levenshteinDistance(
text.replace(/\W/g, ''),
(statMap[key] ?? '').replace(/\W/g, '')
),
])
}
return results
return getBestKeyDist(kdist)
}
export function parseMainStatValues(
texts: string[]
Expand Down Expand Up @@ -108,35 +116,26 @@ export function parseSubstats(texts: string[]): ISubstat[] {
return matches.slice(0, 4)
}

type Ham = [LocationCharacterKey, number]
export function parseLocation(texts: string[]): LocationCharacterKey {
const hams: Array<Ham> = []
const kdist: Array<KeyDist<LocationCharacterKey>> = []
for (let text of texts) {
if (!text) continue
const colonInd = text.indexOf(':')
if (colonInd !== -1) text = text.slice(colonInd + 1)
if (!text) continue

for (const key of allLocationCharacterKeys)
hams.push([
kdist.push([
key,
hammingDistance(
levenshteinDistance(
text.replace(/\W/g, ''),
key //TODO: use the translated character name?
),
])
}
const [key] = hams.reduce(
(accu: Ham, curr: Ham) => {
const [, val] = accu
const [, curVal] = curr
if (curVal < val) return curr
return accu
},
[
'Traveler', // traveler is the default value when we don't recognize the name
8,
] as [LocationCharacterKey, number]
)
return key

// traveler is the default value when we don't recognize the name
kdist.push(['Traveler', 8])
const [char] = getBestKeyDist(kdist)
return char
}
Loading

0 comments on commit ed76079

Please sign in to comment.