(
code: string,
options: GenerateOptions = {}
)
| 11 | } |
| 12 | |
| 13 | export 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 | } |
no test coverage detected