Skip to content

Commit 942926b

Browse files
committed
fix: remove growth percentage
1 parent f4beb99 commit 942926b

7 files changed

Lines changed: 12 additions & 82 deletions

File tree

app/utils/charts.ts

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -131,55 +131,6 @@ export type LineChartAnalysis = {
131131
volatility: 'very_stable' | 'moderate' | 'volatile' | 'undefined'
132132
trend: 'strong' | 'weak' | 'none' | 'undefined'
133133
}
134-
progressionPercent: number | null
135-
}
136-
137-
export function computeOverallProgressionPercentUsingLinearTrend(
138-
indexedValues: Array<{ value: number; index: number }>,
139-
yValues: number[],
140-
): number | null {
141-
const count = indexedValues.length
142-
if (count < 2) return null
143-
if (yValues.length !== count) return null
144-
145-
let sumX = 0
146-
let sumY = 0
147-
let sumXY = 0
148-
let sumXX = 0
149-
150-
for (let i = 0; i < count; i += 1) {
151-
const entry = indexedValues[i]
152-
const y = yValues[i]
153-
if (entry === undefined || y === undefined) continue
154-
const x = entry.index
155-
sumX += x
156-
sumY += y
157-
sumXY += x * y
158-
sumXX += x * x
159-
}
160-
161-
const denominator = count * sumXX - sumX * sumX
162-
if (denominator === 0) return null
163-
164-
const slope = (count * sumXY - sumX * sumY) / denominator
165-
const intercept = (sumY - slope * sumX) / count
166-
167-
const firstIndex = indexedValues[0]?.index
168-
const lastIndex = indexedValues[count - 1]?.index
169-
if (firstIndex === undefined || lastIndex === undefined) return null
170-
171-
const predictedStart = slope * firstIndex + intercept
172-
const predictedEnd = slope * lastIndex + intercept
173-
const delta = predictedEnd - predictedStart
174-
175-
const meanLevel = sumY / count
176-
177-
const absolutePredictedStart = Math.abs(predictedStart)
178-
const denominatorForPercent = absolutePredictedStart >= 1e-12 ? predictedStart : meanLevel
179-
180-
if (denominatorForPercent === 0) return null
181-
182-
return (delta / denominatorForPercent) * 100
183134
}
184135

185136
/**
@@ -240,7 +191,6 @@ export function computeLineChartAnalysis(values: Array<number | null>): LineChar
240191
volatility: 'undefined',
241192
trend: 'undefined',
242193
},
243-
progressionPercent: null,
244194
}
245195
}
246196

@@ -256,7 +206,6 @@ export function computeLineChartAnalysis(values: Array<number | null>): LineChar
256206
volatility: 'very_stable',
257207
trend: 'none',
258208
},
259-
progressionPercent: null,
260209
}
261210
}
262211

@@ -373,11 +322,6 @@ export function computeLineChartAnalysis(values: Array<number | null>): LineChar
373322
}
374323
}
375324

376-
const progressionPercent = computeOverallProgressionPercentUsingLinearTrend(
377-
indexedValues,
378-
winsorizedYValues,
379-
)
380-
381325
return {
382326
mean,
383327

@@ -423,8 +367,6 @@ export function computeLineChartAnalysis(values: Array<number | null>): LineChar
423367
*/
424368
rSquared,
425369

426-
progressionPercent,
427-
428370
/**
429371
* Human readable trends interpretation from which translations can be generated
430372
*/
@@ -534,10 +476,6 @@ export function createAltTextForTrendLineChart({
534476
end_value: config.formattedDatasetValues[i]?.at(-1) ?? 0,
535477
trend: trendText,
536478
downloads_slope: config.numberFormatter(pkg.slope),
537-
growth_percentage:
538-
pkg.progressionPercent !== null
539-
? `${pkg.progressionPercent.toFixed(1)}%`
540-
: config.$t('package.trends.copy_alt.growth_unavailable'),
541479
})
542480
})
543481
.join(', ')
@@ -561,8 +499,8 @@ export function createAltTextForTrendLineChart({
561499
})} `
562500

563501
const generalAnalysis = config.$t('package.trends.copy_alt.general_description', {
564-
start_date: analysis?.[0]?.dates[0]?.text,
565-
end_date: analysis?.[0]?.dates.at(-1)?.text,
502+
start_date: analysis?.[0]?.dates[0]?.text ?? '-',
503+
end_date: analysis?.[0]?.dates.at(-1)?.text ?? '-',
566504
granularity,
567505
packages_analysis,
568506
watermark: config.$t('package.trends.copy_alt.watermark'),

i18n/locales/en.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,12 @@
382382
"trend_undefined": "undefined (insufficient data)",
383383
"button_label": "Copy alt text",
384384
"watermark": "At the bottom, a watermark reads \"./npmx a fast, modern browser for the npm registry\"",
385-
"analysis": "{package_name} starts at {start_value} and ends at {end_value}, showing a {trend} trend with a slope of {downloads_slope} downloads per time interval, and an overall {growth_percentage} growth",
385+
"analysis": "{package_name} starts at {start_value} and ends at {end_value}, showing a {trend} trend with a slope of {downloads_slope} downloads per time interval",
386386
"estimation": "The final value is an estimate based on partial data for the current period.",
387387
"estimations": "The final values are estimates based on partial data for the current period.",
388388
"compare": "Package download comparison line chart for: {packages}.",
389389
"single_package": "Downloads line chart for the {package} package.",
390-
"general_description": "The Y axis represents the number of downloads. The X axis represents the date range, from {start_date} to {end_date}, with a {granularity} time period.{estimation_notice} {packages_analysis}. {watermark}.",
391-
"growth_unavailable": "N/A"
390+
"general_description": "The Y axis represents the number of downloads. The X axis represents the date range, from {start_date} to {end_date}, with a {granularity} time period.{estimation_notice} {packages_analysis}. {watermark}."
392391
}
393392
},
394393
"downloads": {

i18n/locales/fr-FR.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,12 @@
382382
"trend_undefined": "indéfinie (données insuffisantes)",
383383
"button_label": "Copier le texte alternatif",
384384
"watermark": "En bas, un filigrane indique \"./npmx un navigateur rapide et moderne pour le registre npm\"",
385-
"analysis": "{package_name} commence à {start_value} et se termine à {end_value}, affichant une tendance {trend} avec une pente de {downloads_slope} téléchargements par intervalle de temps, et une croissance globale de {growth_percentage}",
385+
"analysis": "{package_name} commence à {start_value} et se termine à {end_value}, affichant une tendance {trend} avec une pente de {downloads_slope} téléchargements par intervalle de temps",
386386
"estimation": "La valeur finale est une estimation basée sur des données partielles pour la période en cours.",
387387
"estimations": "Les valeurs finales sont des estimations basées sur des données partielles pour la période en cours.",
388388
"compare": "Graphique en courbes comparant les téléchargements des paquets suivants : {packages}.",
389389
"single_package": "Graphique en courbes des téléchargements pour le paquet {package}.",
390-
"general_description": "L’axe Y représente le nombre de téléchargements. L’axe X représente la plage de dates, de {start_date} à {end_date}, avec une période de temps {granularity}.{estimation_notice} {packages_analysis}. {watermark}.",
391-
"growth_unavailable": "N/A"
390+
"general_description": "L’axe Y représente le nombre de téléchargements. L’axe X représente la plage de dates, de {start_date} à {end_date}, avec une période de temps {granularity}.{estimation_notice} {packages_analysis}. {watermark}."
392391
}
393392
},
394393
"downloads": {

i18n/schema.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,9 +1167,6 @@
11671167
},
11681168
"general_description": {
11691169
"type": "string"
1170-
},
1171-
"growth_unavailable": {
1172-
"type": "string"
11731170
}
11741171
},
11751172
"additionalProperties": false

lunaria/files/en-GB.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,12 @@
381381
"trend_undefined": "undefined (insufficient data)",
382382
"button_label": "Copy alt text",
383383
"watermark": "At the bottom, a watermark reads \"./npmx a fast, modern browser for the npm registry\"",
384-
"analysis": "{package_name} starts at {start_value} and ends at {end_value}, showing a {trend} trend with a slope of {downloads_slope} downloads per time interval, and an overall {growth_percentage} growth",
384+
"analysis": "{package_name} starts at {start_value} and ends at {end_value}, showing a {trend} trend with a slope of {downloads_slope} downloads per time interval",
385385
"estimation": "The final value is an estimate based on partial data for the current period.",
386386
"estimations": "The final values are estimates based on partial data for the current period.",
387387
"compare": "Package download comparison line chart for: {packages}.",
388388
"single_package": "Downloads line chart for the {package} package.",
389-
"general_description": "The Y axis represents the number of downloads. The X axis represents the date range, from {start_date} to {end_date}, with a {granularity} time period.{estimation_notice} {packages_analysis}. {watermark}.",
390-
"growth_unavailable": "N/A"
389+
"general_description": "The Y axis represents the number of downloads. The X axis represents the date range, from {start_date} to {end_date}, with a {granularity} time period.{estimation_notice} {packages_analysis}. {watermark}."
391390
}
392391
},
393392
"downloads": {

lunaria/files/en-US.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,12 @@
381381
"trend_undefined": "undefined (insufficient data)",
382382
"button_label": "Copy alt text",
383383
"watermark": "At the bottom, a watermark reads \"./npmx a fast, modern browser for the npm registry\"",
384-
"analysis": "{package_name} starts at {start_value} and ends at {end_value}, showing a {trend} trend with a slope of {downloads_slope} downloads per time interval, and an overall {growth_percentage} growth",
384+
"analysis": "{package_name} starts at {start_value} and ends at {end_value}, showing a {trend} trend with a slope of {downloads_slope} downloads per time interval",
385385
"estimation": "The final value is an estimate based on partial data for the current period.",
386386
"estimations": "The final values are estimates based on partial data for the current period.",
387387
"compare": "Package download comparison line chart for: {packages}.",
388388
"single_package": "Downloads line chart for the {package} package.",
389-
"general_description": "The Y axis represents the number of downloads. The X axis represents the date range, from {start_date} to {end_date}, with a {granularity} time period.{estimation_notice} {packages_analysis}. {watermark}.",
390-
"growth_unavailable": "N/A"
389+
"general_description": "The Y axis represents the number of downloads. The X axis represents the date range, from {start_date} to {end_date}, with a {granularity} time period.{estimation_notice} {packages_analysis}. {watermark}."
391390
}
392391
},
393392
"downloads": {

lunaria/files/fr-FR.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,12 @@
381381
"trend_undefined": "indéfinie (données insuffisantes)",
382382
"button_label": "Copier le texte alternatif",
383383
"watermark": "En bas, un filigrane indique \"./npmx un navigateur rapide et moderne pour le registre npm\"",
384-
"analysis": "{package_name} commence à {start_value} et se termine à {end_value}, affichant une tendance {trend} avec une pente de {downloads_slope} téléchargements par intervalle de temps, et une croissance globale de {growth_percentage}",
384+
"analysis": "{package_name} commence à {start_value} et se termine à {end_value}, affichant une tendance {trend} avec une pente de {downloads_slope} téléchargements par intervalle de temps",
385385
"estimation": "La valeur finale est une estimation basée sur des données partielles pour la période en cours.",
386386
"estimations": "Les valeurs finales sont des estimations basées sur des données partielles pour la période en cours.",
387387
"compare": "Graphique en courbes comparant les téléchargements des paquets suivants : {packages}.",
388388
"single_package": "Graphique en courbes des téléchargements pour le paquet {package}.",
389-
"general_description": "L’axe Y représente le nombre de téléchargements. L’axe X représente la plage de dates, de {start_date} à {end_date}, avec une période de temps {granularity}.{estimation_notice} {packages_analysis}. {watermark}.",
390-
"growth_unavailable": "N/A"
389+
"general_description": "L’axe Y représente le nombre de téléchargements. L’axe X représente la plage de dates, de {start_date} à {end_date}, avec une période de temps {granularity}.{estimation_notice} {packages_analysis}. {watermark}."
391390
}
392391
},
393392
"downloads": {

0 commit comments

Comments
 (0)