Added progress calculation for sections & texts; covered corner cases
This commit is contained in:
parent
8534163e55
commit
ebc7a5708b
@ -60,6 +60,54 @@ public static class TranslationProcessor
|
|||||||
var numTotalTranslations = numCultures * numTextElements;
|
var numTotalTranslations = numCultures * numTextElements;
|
||||||
var numTextElementsTranslated = await db.Translations.CountAsync(n => !string.IsNullOrWhiteSpace(n.Text));
|
var numTextElementsTranslated = await db.Translations.CountAsync(n => !string.IsNullOrWhiteSpace(n.Text));
|
||||||
|
|
||||||
|
if(numTextElementsTranslated == 0 && numTotalTranslations == 0)
|
||||||
|
return new ProcessorResult<int>(100);
|
||||||
|
|
||||||
|
if (numTotalTranslations == 0)
|
||||||
|
return new ProcessorResult<int>(0);
|
||||||
|
|
||||||
|
if(numTextElementsTranslated > numTotalTranslations)
|
||||||
|
return new ProcessorResult<int>(100);
|
||||||
|
|
||||||
|
return new ProcessorResult<int>(numTextElementsTranslated * 100 / numTotalTranslations);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<ProcessorResult<int>> CalculateTranslationProgress(Section section)
|
||||||
|
{
|
||||||
|
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||||
|
var numCultures = (await AppSettings.GetCultureIndices()).Count;
|
||||||
|
var numTextElements = await db.TextElements.CountAsync(n => n.Section == section);
|
||||||
|
var numTotalTranslations = numCultures * numTextElements;
|
||||||
|
var numTextElementsTranslated = await db.Translations.CountAsync(n => !string.IsNullOrWhiteSpace(n.Text) && n.TextElement.Section == section);
|
||||||
|
|
||||||
|
if(numTextElementsTranslated == 0 && numTotalTranslations == 0)
|
||||||
|
return new ProcessorResult<int>(100);
|
||||||
|
|
||||||
|
if (numTotalTranslations == 0)
|
||||||
|
return new ProcessorResult<int>(0);
|
||||||
|
|
||||||
|
if(numTextElementsTranslated > numTotalTranslations)
|
||||||
|
return new ProcessorResult<int>(100);
|
||||||
|
|
||||||
|
return new ProcessorResult<int>(numTextElementsTranslated * 100 / numTotalTranslations);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<ProcessorResult<int>> CalculateTranslationProgress(TextElement textElement)
|
||||||
|
{
|
||||||
|
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||||
|
var numCultures = (await AppSettings.GetCultureIndices()).Count;
|
||||||
|
var numTotalTranslations = numCultures;
|
||||||
|
var numTextElementsTranslated = await db.Translations.CountAsync(n => !string.IsNullOrWhiteSpace(n.Text) && n.TextElement == textElement);
|
||||||
|
|
||||||
|
if(numTextElementsTranslated == 0 && numTotalTranslations == 0)
|
||||||
|
return new ProcessorResult<int>(100);
|
||||||
|
|
||||||
|
if (numTotalTranslations == 0)
|
||||||
|
return new ProcessorResult<int>(0);
|
||||||
|
|
||||||
|
if(numTextElementsTranslated > numTotalTranslations)
|
||||||
|
return new ProcessorResult<int>(100);
|
||||||
|
|
||||||
return new ProcessorResult<int>(numTextElementsTranslated * 100 / numTotalTranslations);
|
return new ProcessorResult<int>(numTextElementsTranslated * 100 / numTotalTranslations);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user