@@ -11,6 +11,7 @@ import {
1111} from "../db" ;
1212import { constraintsLabel , OTV } from "./constraints" ;
1313import { percentage , timeRemaining } from "../utils/util" ;
14+ import { NoLocation } from "../types" ;
1415
1516export const scoreCandidate = async (
1617 constraints : OTV ,
@@ -94,7 +95,9 @@ export const scoreCandidate = async (
9495 ( 1 - scaledFaults ) * constraints . WEIGHT_CONFIG . FAULTS_WEIGHT ;
9596
9697 const latestCandidateLocation = await queries . getCandidateLocation (
98+ candidate . slotId ,
9799 candidate . name ,
100+ candidate . stash ,
98101 ) ;
99102
100103 const provider = latestCandidateLocation ?. provider || "No Provider" ;
@@ -116,7 +119,9 @@ export const scoreCandidate = async (
116119 scaledDefined ( candidateLocation , locationValues , 0 , 1 ) || 0 ;
117120 const locationScore = bannedProvider
118121 ? 0
119- : latestCandidateLocation ?. city == "No Location"
122+ : latestCandidateLocation ?. city == NoLocation . NoLocation ||
123+ ! latestCandidateLocation ||
124+ ! latestCandidateLocation ?. city
120125 ? 0.25 * constraints . WEIGHT_CONFIG . LOCATION_WEIGHT
121126 : ( 1 - scaledLocation ) * constraints . WEIGHT_CONFIG . LOCATION_WEIGHT || 0 ;
122127
@@ -135,7 +140,9 @@ export const scoreCandidate = async (
135140 scaledDefined ( candidateRegion , regionValues , 0 , 1 ) || 0 ;
136141 const regionScore = bannedProvider
137142 ? 0
138- : latestCandidateLocation ?. region == "No Location"
143+ : latestCandidateLocation ?. region == NoLocation . NoLocation ||
144+ ! latestCandidateLocation ||
145+ ! latestCandidateLocation ?. region
139146 ? 0.25 * constraints . WEIGHT_CONFIG . REGION_WEIGHT
140147 : ( 1 - scaledRegion ) * constraints . WEIGHT_CONFIG . REGION_WEIGHT || 0 ;
141148
@@ -154,7 +161,9 @@ export const scoreCandidate = async (
154161 scaledDefined ( candidateCountry , countryValues , 0 , 1 ) || 0 ;
155162 const countryScore = bannedProvider
156163 ? 0
157- : latestCandidateLocation ?. country == "No Location"
164+ : latestCandidateLocation ?. country == NoLocation . NoLocation ||
165+ ! latestCandidateLocation ||
166+ ! latestCandidateLocation ?. country
158167 ? 0.25 * constraints . WEIGHT_CONFIG . COUNTRY_WEIGHT
159168 : ( 1 - scaledCountry ) * constraints . WEIGHT_CONFIG . COUNTRY_WEIGHT || 0 ;
160169
@@ -173,7 +182,9 @@ export const scoreCandidate = async (
173182 scaledDefined ( candidateProvider , providerValues , 0 , 1 ) || 0 ;
174183 const providerScore = bannedProvider
175184 ? 0
176- : latestCandidateLocation ?. provider == "No Location"
185+ : latestCandidateLocation ?. provider == "No Location" ||
186+ ! latestCandidateLocation ||
187+ ! latestCandidateLocation ?. provider
177188 ? 0.25 * constraints . WEIGHT_CONFIG . PROVIDER_WEIGHT
178189 : ( 1 - scaledProvider ) * constraints . WEIGHT_CONFIG . PROVIDER_WEIGHT || 0 ;
179190
0 commit comments