feat: Update package references and enhance AI extraction service with CSV output functionality
This commit is contained in:
parent
55e8f0face
commit
af74c90ce7
12 changed files with 400 additions and 153 deletions
|
|
@ -198,20 +198,7 @@ public class AiExtractionService : IAiExtractionService
|
|||
{
|
||||
try
|
||||
{
|
||||
var dir = Path.GetDirectoryName(request.CsvOutputPath) ?? string.Empty;
|
||||
if (!string.IsNullOrWhiteSpace(dir) && !Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
using var sw = new StreamWriter(request.CsvOutputPath, false, Encoding.UTF8);
|
||||
sw.WriteLine("Path,Text");
|
||||
foreach (var r in extractedResults)
|
||||
{
|
||||
var csvFileName = Path.GetFileName(r.Path ?? string.Empty);
|
||||
var safeText = (r.Text ?? string.Empty).Replace("\"", "\"\"");
|
||||
sw.WriteLine($"\"{csvFileName}\",\"{safeText}\"");
|
||||
}
|
||||
WriteCsvOutput(request.CsvOutputPath, extractedResults);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -222,6 +209,24 @@ public class AiExtractionService : IAiExtractionService
|
|||
return summary;
|
||||
}
|
||||
|
||||
internal static void WriteCsvOutput(string csvOutputPath, IEnumerable<AiResultItem> extractedResults)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(csvOutputPath) ?? string.Empty;
|
||||
if (!string.IsNullOrWhiteSpace(dir) && !Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
using var sw = new StreamWriter(csvOutputPath, false, Encoding.UTF8);
|
||||
sw.WriteLine("filename,text");
|
||||
foreach (var result in extractedResults)
|
||||
{
|
||||
var csvFileName = Path.GetFileName(result.Path ?? string.Empty);
|
||||
var safeText = (result.Text ?? string.Empty).Replace("\"", "\"\"");
|
||||
sw.WriteLine($"\"{csvFileName}\",\"{safeText}\"");
|
||||
}
|
||||
}
|
||||
|
||||
private static double CalculateAverageImagesPerSecond(int processed, TimeSpan elapsed)
|
||||
{
|
||||
return elapsed.TotalSeconds > 0 ? processed / elapsed.TotalSeconds : 0;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ public static class PickerPreferenceKeys
|
|||
public const string LogoFile = "Picker.LogoFile.LastPath";
|
||||
public const string ModelsFolder = "Picker.ModelsFolder.LastPath";
|
||||
public const string CsvOutput = "Picker.CsvOutput.LastPath";
|
||||
public const string SettingsFile = "Picker.SettingsFile.LastPath";
|
||||
public const string LastSettingsFile = "Settings.LastFilePath";
|
||||
public const string FaceExecutableFolder = "Picker.FaceExecutableFolder.LastPath";
|
||||
public const string FaceOutputFolder = "Picker.FaceOutputFolder.LastPath";
|
||||
public const string FaceMatcherExecutable = "Picker.FaceMatcherExecutable.LastPath";
|
||||
|
|
@ -61,6 +63,33 @@ public sealed class PickerPreferenceService
|
|||
_userPreferences.SalvaParametriSetup();
|
||||
}
|
||||
|
||||
public string? GetRememberedValue(string preferenceKey)
|
||||
{
|
||||
var value = _userPreferences.LeggiParametroString(preferenceKey);
|
||||
return string.IsNullOrWhiteSpace(value)
|
||||
? null
|
||||
: value.Trim().Trim('"');
|
||||
}
|
||||
|
||||
public void RememberValue(string preferenceKey, string? value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_userPreferences.AggiornaParametro(preferenceKey, value.Trim().Trim('"'));
|
||||
_userPreferences.SalvaParametriSetup();
|
||||
}
|
||||
|
||||
public void ForgetValue(string preferenceKey)
|
||||
{
|
||||
if (_userPreferences.RimuoviParametro(preferenceKey))
|
||||
{
|
||||
_userPreferences.SalvaParametriSetup();
|
||||
}
|
||||
}
|
||||
|
||||
private string? GetPreferredStartDirectory(string preferenceKey, string? currentPath)
|
||||
{
|
||||
var storedPath = _userPreferences.LeggiParametroString(preferenceKey);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue