From abbe2feac0d044f2d73601e5337972004f9e66a6 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Sat, 18 May 2024 10:26:36 -0700 Subject: [PATCH] Removed Amazon IsOffsetDeterministicHashCode --- Rename/Models/AppSettings.cs | 1 - Rename/Models/Binder/AppSettings.cs | 2 - Rename/Rename.cs | 98 -------------------------- Shared/Models/Aggregations.cs | 19 ----- Shared/Models/AllPerson.cs | 15 ---- Shared/Models/ClusterId.cs | 15 ---- Shared/Models/ContentProperties.cs | 20 ------ Shared/Models/ContentSignature.cs | 14 ---- Shared/Models/Datum.cs | 45 ------------ Shared/Models/ImageAmazon.cs | 36 ---------- Shared/Models/LocationAmazon.cs | 15 ---- Shared/Models/LocationInfo.cs | 17 ----- Shared/Models/ParentMap.cs | 13 ---- Shared/Models/PersonAmazon.cs | 15 ---- Shared/Models/RootAmazon.cs | 15 ---- Shared/Models/SearchData.cs | 16 ----- Shared/Models/Stateless/Id.cs | 3 +- Shared/Models/Stateless/Methods/IId.cs | 5 ++ Shared/Models/Thing.cs | 15 ---- Shared/Models/Time.cs | 15 ---- Shared/Models/Type.cs | 15 ---- Shared/Models/XAccntParentMap.cs | 13 ---- 22 files changed, 7 insertions(+), 415 deletions(-) delete mode 100644 Shared/Models/Aggregations.cs delete mode 100644 Shared/Models/AllPerson.cs delete mode 100644 Shared/Models/ClusterId.cs delete mode 100644 Shared/Models/ContentProperties.cs delete mode 100644 Shared/Models/ContentSignature.cs delete mode 100644 Shared/Models/Datum.cs delete mode 100644 Shared/Models/ImageAmazon.cs delete mode 100644 Shared/Models/LocationAmazon.cs delete mode 100644 Shared/Models/LocationInfo.cs delete mode 100644 Shared/Models/ParentMap.cs delete mode 100644 Shared/Models/PersonAmazon.cs delete mode 100644 Shared/Models/RootAmazon.cs delete mode 100644 Shared/Models/SearchData.cs delete mode 100644 Shared/Models/Thing.cs delete mode 100644 Shared/Models/Time.cs delete mode 100644 Shared/Models/Type.cs delete mode 100644 Shared/Models/XAccntParentMap.cs diff --git a/Rename/Models/AppSettings.cs b/Rename/Models/AppSettings.cs index 9d605c3..0ff0b44 100644 --- a/Rename/Models/AppSettings.cs +++ b/Rename/Models/AppSettings.cs @@ -4,7 +4,6 @@ using System.Text.Json.Serialization; namespace View_by_Distance.Rename.Models; public record AppSettings(string Company, - string? HarFilesDirectory, int MaxDegreeOfParallelism, bool RequireRootDirectoryExists) { diff --git a/Rename/Models/Binder/AppSettings.cs b/Rename/Models/Binder/AppSettings.cs index bf1824d..e97f4e4 100644 --- a/Rename/Models/Binder/AppSettings.cs +++ b/Rename/Models/Binder/AppSettings.cs @@ -8,7 +8,6 @@ public class AppSettings { public string? Company { get; set; } - public string? HarFilesDirectory { get; set; } public int? MaxDegreeOfParallelism { get; set; } public bool? RequireRootDirectoryExists { get; set; } @@ -48,7 +47,6 @@ public class AppSettings if (appSettings.RequireRootDirectoryExists is null) throw new NullReferenceException(nameof(appSettings.RequireRootDirectoryExists)); Verify(appSettings); result = new(appSettings.Company, - appSettings.HarFilesDirectory, appSettings.MaxDegreeOfParallelism.Value, appSettings.RequireRootDirectoryExists.Value); return result; diff --git a/Rename/Rename.cs b/Rename/Rename.cs index a72a605..142726e 100644 --- a/Rename/Rename.cs +++ b/Rename/Rename.cs @@ -385,102 +385,6 @@ public partial class Rename : IRename _ = IPath.WriteAllText(Path.Combine(aMetadataCollectionDirectory, $"{ticks}.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null); } - private static ReadOnlyCollection<(string, string)> GetAggregationLines(string harFile) - { - List<(string, string)> results = []; - if (!File.Exists(harFile)) - throw new Exception(); - string lastUrl = string.Empty; - string text = "\"text\": \"{"; - string[] lines = File.ReadAllLines(harFile); - foreach (string line in lines) - { - if (line.Contains("\"url\": \"")) - lastUrl = line; - if (!line.Contains(text)) - continue; - if (!line.Contains("aggregations")) - continue; - if (lastUrl.Contains("search?asset=NONE")) - continue; - results.Add(new(lastUrl, line.Trim()[(text.Length - 1)..^1].Replace("\\\"", "\""))); - lastUrl = string.Empty; - } - return new(results); - } - - private static void SaveAmazon(IReadOnlyList data, string personIdFile) - { - string json; - Dictionary keyValuePairs = []; - foreach (Datum datum in data) - _ = keyValuePairs.TryAdd(datum.Name.Split('.')[0], datum); - json = JsonSerializer.Serialize(keyValuePairs, DictionaryDatumGenerationContext.Default.DictionaryStringDatum); - File.WriteAllText(personIdFile, json); - } - - private static void SaveAmazon(AppSettings appSettings, string harFile) - { - if (string.IsNullOrEmpty(appSettings.HarFilesDirectory)) - throw new NullReferenceException(nameof(appSettings.HarFilesDirectory)); - string offset; - string personId; - RootAmazon amazon; - string? personName; - string personIdFile; - string personDirectory; - PersonAmazon personAmazon; - Dictionary keyValuePairs = []; - ReadOnlyCollection<(string Url, string AggregationLine)> aggregationLines = GetAggregationLines(harFile); - foreach ((string url, string aggregationLine) in aggregationLines) - { - if (aggregationLine.Contains(",\"category\":\"allPeople\"}")) - continue; - amazon = JsonSerializer.Deserialize(aggregationLine, RootAmazonGenerationContext.Default.RootAmazon) ?? throw new Exception(); - if (amazon.Aggregations?.People is null || amazon.Aggregations.People.Count < 1) - continue; - personAmazon = amazon.Aggregations.People[0]; - if (!url.Contains(personAmazon.Match)) - continue; - personDirectory = Path.Combine(appSettings.HarFilesDirectory, "Amazon", personAmazon.SearchData.ClusterName); - _ = Directory.CreateDirectory(personDirectory); - personIdFile = Path.Combine(personDirectory, $"000) {personAmazon.Match}.json"); - _ = keyValuePairs.TryAdd(personAmazon.Match, personAmazon.SearchData.ClusterName); - SaveAmazon(amazon.Data, personIdFile); - } - foreach ((string url, string aggregationLine) in aggregationLines) - { - if (aggregationLine.Contains(",\"category\":\"allPeople\"}")) - continue; - amazon = JsonSerializer.Deserialize(aggregationLine, RootAmazonGenerationContext.Default.RootAmazon) ?? throw new Exception(); - if (amazon.Aggregations?.People is not null && amazon.Aggregations.People.Count > 0) - continue; - if (!url.Contains("offset=")) - continue; - offset = url.Split("offset=")[1]; - if (!url.Contains("people%3A(")) - continue; - personId = url.Split("people%3A(")[1].Split(')')[0]; - if (!keyValuePairs.TryGetValue(personId, out personName)) - continue; - personDirectory = Path.Combine(appSettings.HarFilesDirectory, "Amazon", personName); - _ = Directory.CreateDirectory(personDirectory); - personIdFile = Path.Combine(personDirectory, $"{offset.Split('&')[0]}) {personId}.json"); - SaveAmazon(amazon.Data, personIdFile); - } - } - - private static void SaveAmazon(ILogger? logger, AppSettings appSettings, long ticks) - { - if (string.IsNullOrEmpty(appSettings.HarFilesDirectory)) - throw new NullReferenceException(nameof(appSettings.HarFilesDirectory)); - logger?.LogInformation("{Ticks} a", ticks); - string[] harFiles = Directory.GetFiles(appSettings.HarFilesDirectory, "*.har", SearchOption.TopDirectoryOnly); - foreach (string harFile in harFiles) - SaveAmazon(appSettings, harFile); - logger?.LogInformation("{harFiles} count", harFiles.Length); - } - private void RenameWork(ILogger? logger, AppSettings appSettings, IRename rename, long ticks, RenameConfiguration renameConfiguration) { string aMetadataCollectionDirectory = IResult.GetResultsDateGroupDirectory(renameConfiguration.MetadataConfiguration.ResultConfiguration, nameof(A_Metadata), renameConfiguration.MetadataConfiguration.ResultConfiguration.ResultCollection); @@ -491,8 +395,6 @@ public partial class Rename : IRename throw new Exception($"Invalid {nameof(renameConfiguration.RelativePropertyCollectionFile)}"); DirectoryInfo directoryInfo = new(Path.GetFullPath(renameConfiguration.MetadataConfiguration.ResultConfiguration.RootDirectory)); logger?.LogInformation("{Ticks} {RootDirectory}", ticks, directoryInfo.FullName); - if (!string.IsNullOrEmpty(appSettings.HarFilesDirectory) && Directory.Exists(appSettings.HarFilesDirectory)) - SaveAmazon(logger, appSettings, ticks); ReadOnlyCollection records = GetExifDirectoryCollection(rename, appSettings, renameConfiguration, directoryInfo); SaveIdentifiersToDisk(ticks, renameConfiguration, aMetadataCollectionDirectory, records); ReadOnlyCollection toDoCollection = GetToDoCollection(renameConfiguration, identifiers, records); diff --git a/Shared/Models/Aggregations.cs b/Shared/Models/Aggregations.cs deleted file mode 100644 index 5182aab..0000000 --- a/Shared/Models/Aggregations.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Text.Json.Serialization; - -namespace View_by_Distance.Shared.Models; - -public record Aggregations( - [property: JsonPropertyName("allPeople")] IReadOnlyList AllPeople, - [property: JsonPropertyName("clusterId")] IReadOnlyList ClusterId, - [property: JsonPropertyName("location")] IReadOnlyList Location, - [property: JsonPropertyName("people")] IReadOnlyList People, - [property: JsonPropertyName("things")] IReadOnlyList Things, - [property: JsonPropertyName("time")] IReadOnlyList