MCPcopy Index your code
hub / github.com/TeaCoder52/patcode / predictCodeQuality

Function predictCodeQuality

src/predictor.ts:13–52  ·  view source on GitHub ↗
(
	code: string,
	options: GenerateOptions = {}
)

Source from the content-addressed store, hash-verified

11}
12
13export function predictCodeQuality(
14 code: string,
15 options: GenerateOptions = {}
16): CodePrediction {
17 const a = analyze(code)
18
19 let baseMem = 0.5
20 if (a.memorability === 'low') baseMem = 0.25
21 if (a.memorability === 'medium') baseMem = 0.55
22 if (a.memorability === 'high') baseMem = 0.85
23
24 switch (options.profile) {
25 case 'children':
26 baseMem += 0.1
27 break
28 case 'elderly':
29 if (a.entropy > 10) baseMem -= 0.1
30 break
31 case 'asia':
32 if (code.includes('4')) baseMem -= 0.15
33 break
34 case 'latam':
35 if (a.memorability === 'high') baseMem += 0.05
36 break
37 default:
38 break
39 }
40
41 let confusion = 0
42 if (options.previousCode && options.previousCode.length === code.length) {
43 confusion = hammingSimilarity(code, options.previousCode)
44 }
45
46 const clamp = (v: number) => Math.max(0, Math.min(1, v))
47
48 return {
49 memorabilityScore: clamp(baseMem),
50 confusionScore: clamp(confusion),
51 }
52}

Callers 2

isProfileCompatibleFunction · 0.90
isPredictionCompatibleFunction · 0.90

Calls 3

analyzeFunction · 0.90
hammingSimilarityFunction · 0.85
clampFunction · 0.85

Tested by

no test coverage detected