Removed Amazon

IsOffsetDeterministicHashCode
This commit is contained in:
Mike Phares 2024-05-18 10:26:36 -07:00
parent d1557e1d85
commit abbe2feac0
22 changed files with 7 additions and 415 deletions

View File

@ -4,7 +4,6 @@ using System.Text.Json.Serialization;
namespace View_by_Distance.Rename.Models; namespace View_by_Distance.Rename.Models;
public record AppSettings(string Company, public record AppSettings(string Company,
string? HarFilesDirectory,
int MaxDegreeOfParallelism, int MaxDegreeOfParallelism,
bool RequireRootDirectoryExists) bool RequireRootDirectoryExists)
{ {

View File

@ -8,7 +8,6 @@ public class AppSettings
{ {
public string? Company { get; set; } public string? Company { get; set; }
public string? HarFilesDirectory { get; set; }
public int? MaxDegreeOfParallelism { get; set; } public int? MaxDegreeOfParallelism { get; set; }
public bool? RequireRootDirectoryExists { 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)); if (appSettings.RequireRootDirectoryExists is null) throw new NullReferenceException(nameof(appSettings.RequireRootDirectoryExists));
Verify(appSettings); Verify(appSettings);
result = new(appSettings.Company, result = new(appSettings.Company,
appSettings.HarFilesDirectory,
appSettings.MaxDegreeOfParallelism.Value, appSettings.MaxDegreeOfParallelism.Value,
appSettings.RequireRootDirectoryExists.Value); appSettings.RequireRootDirectoryExists.Value);
return result; return result;

View File

@ -385,102 +385,6 @@ public partial class Rename : IRename
_ = IPath.WriteAllText(Path.Combine(aMetadataCollectionDirectory, $"{ticks}.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null); _ = 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<Datum> data, string personIdFile)
{
string json;
Dictionary<string, Datum> 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<string, string> 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<Program>? 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<Program>? logger, AppSettings appSettings, IRename rename, long ticks, RenameConfiguration renameConfiguration) private void RenameWork(ILogger<Program>? logger, AppSettings appSettings, IRename rename, long ticks, RenameConfiguration renameConfiguration)
{ {
string aMetadataCollectionDirectory = IResult.GetResultsDateGroupDirectory(renameConfiguration.MetadataConfiguration.ResultConfiguration, nameof(A_Metadata), renameConfiguration.MetadataConfiguration.ResultConfiguration.ResultCollection); 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)}"); throw new Exception($"Invalid {nameof(renameConfiguration.RelativePropertyCollectionFile)}");
DirectoryInfo directoryInfo = new(Path.GetFullPath(renameConfiguration.MetadataConfiguration.ResultConfiguration.RootDirectory)); DirectoryInfo directoryInfo = new(Path.GetFullPath(renameConfiguration.MetadataConfiguration.ResultConfiguration.RootDirectory));
logger?.LogInformation("{Ticks} {RootDirectory}", ticks, directoryInfo.FullName); logger?.LogInformation("{Ticks} {RootDirectory}", ticks, directoryInfo.FullName);
if (!string.IsNullOrEmpty(appSettings.HarFilesDirectory) && Directory.Exists(appSettings.HarFilesDirectory))
SaveAmazon(logger, appSettings, ticks);
ReadOnlyCollection<Record> records = GetExifDirectoryCollection(rename, appSettings, renameConfiguration, directoryInfo); ReadOnlyCollection<Record> records = GetExifDirectoryCollection(rename, appSettings, renameConfiguration, directoryInfo);
SaveIdentifiersToDisk(ticks, renameConfiguration, aMetadataCollectionDirectory, records); SaveIdentifiersToDisk(ticks, renameConfiguration, aMetadataCollectionDirectory, records);
ReadOnlyCollection<ToDo> toDoCollection = GetToDoCollection(renameConfiguration, identifiers, records); ReadOnlyCollection<ToDo> toDoCollection = GetToDoCollection(renameConfiguration, identifiers, records);

View File

@ -1,19 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record Aggregations(
[property: JsonPropertyName("allPeople")] IReadOnlyList<AllPerson> AllPeople,
[property: JsonPropertyName("clusterId")] IReadOnlyList<ClusterId> ClusterId,
[property: JsonPropertyName("location")] IReadOnlyList<LocationAmazon> Location,
[property: JsonPropertyName("people")] IReadOnlyList<PersonAmazon> People,
[property: JsonPropertyName("things")] IReadOnlyList<Thing> Things,
[property: JsonPropertyName("time")] IReadOnlyList<Time> Time,
[property: JsonPropertyName("type")] IReadOnlyList<Type> Type
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(Aggregations))]
public partial class AggregationsGenerationContext : JsonSerializerContext
{
}

View File

@ -1,15 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record AllPerson(
[property: JsonPropertyName("count")] int Count,
[property: JsonPropertyName("match")] string Match,
[property: JsonPropertyName("searchData")] SearchData SearchData
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(AllPerson))]
public partial class AllPersonGenerationContext : JsonSerializerContext
{
}

View File

@ -1,15 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record ClusterId(
[property: JsonPropertyName("count")] int Count,
[property: JsonPropertyName("match")] string Match,
[property: JsonPropertyName("searchData")] SearchData SearchData
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(ClusterId))]
public partial class ClusterIdGenerationContext : JsonSerializerContext
{
}

View File

@ -1,20 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record ContentProperties(
[property: JsonPropertyName("contentDate")] DateTime ContentDate,
[property: JsonPropertyName("contentSignatures")] IReadOnlyList<ContentSignature> ContentSignatures,
[property: JsonPropertyName("contentType")] string ContentType,
[property: JsonPropertyName("extension")] string Extension,
[property: JsonPropertyName("image")] ImageAmazon Image,
[property: JsonPropertyName("md5")] string Md5,
[property: JsonPropertyName("size")] int Size,
[property: JsonPropertyName("version")] int Version
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(ContentProperties))]
public partial class ContentPropertiesGenerationContext : JsonSerializerContext
{
}

View File

@ -1,14 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record ContentSignature(
[property: JsonPropertyName("contentSignature")] string Value,
[property: JsonPropertyName("contentSignatureType")] string ContentSignatureType
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(ContentSignature))]
public partial class ContentSignatureGenerationContext : JsonSerializerContext
{
}

View File

@ -1,45 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record Datum(
[property: JsonPropertyName("accessRuleIds")] IReadOnlyList<object> AccessRuleIds,
[property: JsonPropertyName("childAssetTypeInfo")] IReadOnlyList<object> ChildAssetTypeInfo,
[property: JsonPropertyName("contentProperties")] ContentProperties ContentProperties,
[property: JsonPropertyName("createdBy")] string CreatedBy,
[property: JsonPropertyName("createdDate")] DateTime CreatedDate,
[property: JsonPropertyName("eTagResponse")] string ETagResponse,
[property: JsonPropertyName("groupPermissions")] IReadOnlyList<object> GroupPermissions,
[property: JsonPropertyName("id")] string Id,
[property: JsonPropertyName("isRoot")] bool IsRoot,
[property: JsonPropertyName("isShared")] bool IsShared,
[property: JsonPropertyName("keywords")] IReadOnlyList<object> Keywords,
[property: JsonPropertyName("kind")] string Kind,
[property: JsonPropertyName("labels")] IReadOnlyList<object> Labels,
[property: JsonPropertyName("modifiedDate")] DateTime ModifiedDate,
[property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("ownerId")] string OwnerId,
[property: JsonPropertyName("parentMap")] ParentMap ParentMap,
[property: JsonPropertyName("parents")] IReadOnlyList<string> Parents,
[property: JsonPropertyName("protectedFolder")] bool ProtectedFolder,
[property: JsonPropertyName("restricted")] bool Restricted,
[property: JsonPropertyName("status")] string Status,
[property: JsonPropertyName("subKinds")] IReadOnlyList<object> SubKinds,
[property: JsonPropertyName("transforms")] IReadOnlyList<string> Transforms,
[property: JsonPropertyName("version")] int Version,
[property: JsonPropertyName("xAccntParentMap")] XAccntParentMap XAccntParentMap,
[property: JsonPropertyName("xAccntParents")] IReadOnlyList<object> XAccntParents,
[property: JsonPropertyName("match")] bool? Match
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(Datum))]
public partial class DatumGenerationContext : JsonSerializerContext
{
}
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(Dictionary<string, Datum>))]
public partial class DictionaryDatumGenerationContext : JsonSerializerContext
{
}

View File

@ -1,36 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record ImageAmazon(
[property: JsonPropertyName("colorSpace")] string ColorSpace,
[property: JsonPropertyName("dateTime")] DateTime DateTime,
[property: JsonPropertyName("dateTimeDigitized")] DateTime DateTimeDigitized,
[property: JsonPropertyName("dateTimeOriginal")] DateTime DateTimeOriginal,
[property: JsonPropertyName("exposureMode")] string ExposureMode,
[property: JsonPropertyName("exposureProgram")] string ExposureProgram,
[property: JsonPropertyName("exposureTime")] string ExposureTime,
[property: JsonPropertyName("flash")] string Flash,
[property: JsonPropertyName("focalLength")] string FocalLength,
[property: JsonPropertyName("height")] int Height,
[property: JsonPropertyName("make")] string Make,
[property: JsonPropertyName("meteringMode")] string MeteringMode,
[property: JsonPropertyName("model")] string Model,
[property: JsonPropertyName("orientation")] string Orientation,
[property: JsonPropertyName("resolutionUnit")] string ResolutionUnit,
[property: JsonPropertyName("sensingMethod")] string SensingMethod,
[property: JsonPropertyName("sharpness")] string Sharpness,
[property: JsonPropertyName("software")] string Software,
[property: JsonPropertyName("subSecTime")] string SubSecTime,
[property: JsonPropertyName("subSecTimeDigitized")] string SubSecTimeDigitized,
[property: JsonPropertyName("subSecTimeOriginal")] string SubSecTimeOriginal,
[property: JsonPropertyName("whiteBalance")] string WhiteBalance,
[property: JsonPropertyName("width")] int Width,
[property: JsonPropertyName("apertureValue")] string ApertureValue
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(ImageAmazon))]
public partial class ImageAmazonGenerationContext : JsonSerializerContext
{
}

View File

@ -1,15 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record LocationAmazon(
[property: JsonPropertyName("count")] int Count,
[property: JsonPropertyName("match")] string Match,
[property: JsonPropertyName("searchData")] SearchData SearchData
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(LocationAmazon))]
public partial class LocationAmazonGenerationContext : JsonSerializerContext
{
}

View File

@ -1,17 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record LocationInfo(
[property: JsonPropertyName("city")] string City,
[property: JsonPropertyName("country")] string Country,
[property: JsonPropertyName("countryIso3Code")] string CountryIso3Code,
[property: JsonPropertyName("state")] string State,
[property: JsonPropertyName("stateCode")] string StateCode
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(LocationInfo))]
public partial class LocationInfoGenerationContext : JsonSerializerContext
{
}

View File

@ -1,13 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record ParentMap(
[property: JsonPropertyName("FOLDER")] IReadOnlyList<string> FOLDER
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(ParentMap))]
public partial class ParentMapGenerationContext : JsonSerializerContext
{
}

View File

@ -1,15 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record PersonAmazon(
[property: JsonPropertyName("count")] int Count,
[property: JsonPropertyName("match")] string Match,
[property: JsonPropertyName("searchData")] SearchData SearchData
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(PersonAmazon))]
public partial class PersonAmazonGenerationContext : JsonSerializerContext
{
}

View File

@ -1,15 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record RootAmazon(
[property: JsonPropertyName("aggregations")] Aggregations Aggregations,
[property: JsonPropertyName("count")] int Count,
[property: JsonPropertyName("data")] IReadOnlyList<Datum> Data
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(RootAmazon))]
public partial class RootAmazonGenerationContext : JsonSerializerContext
{
}

View File

@ -1,16 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record SearchData(
[property: JsonPropertyName("clusterName")] string ClusterName,
[property: JsonPropertyName("locationId")] string LocationId,
[property: JsonPropertyName("locationInfo")] LocationInfo LocationInfo,
[property: JsonPropertyName("thingId")] string ThingId
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(SearchData))]
public partial class SearchDataGenerationContext : JsonSerializerContext
{
}

View File

@ -1,4 +1,5 @@
using System.Text; using System.Text;
using View_by_Distance.Shared.Models.Stateless.Methods;
namespace View_by_Distance.Shared.Models.Stateless; namespace View_by_Distance.Shared.Models.Stateless;
@ -73,7 +74,7 @@ internal abstract class Id
int check = GetId(metadataConfiguration, intelligentId); int check = GetId(metadataConfiguration, intelligentId);
if (check != id) if (check != id)
throw new NotSupportedException(); throw new NotSupportedException();
result = index is null || metadataConfiguration.Offset == 9876543 ? intelligentId : $"{metadataConfiguration.Offset + index}{intelligentId}"; result = index is null || metadataConfiguration.Offset == IId.DeterministicHashCode ? intelligentId : $"{metadataConfiguration.Offset + index}{intelligentId}";
} }
return result; return result;
} }

View File

@ -3,6 +3,11 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IId public interface IId
{ {
const int DeterministicHashCode = 9876543;
static bool IsOffsetDeterministicHashCode(MetadataConfiguration metadataConfiguration) =>
metadataConfiguration.Offset == DeterministicHashCode;
string TestStatic_GetIntelligentId(MetadataConfiguration metadataConfiguration, long id, bool ignore) => string TestStatic_GetIntelligentId(MetadataConfiguration metadataConfiguration, long id, bool ignore) =>
GetIntelligentId(metadataConfiguration, id, ignore); GetIntelligentId(metadataConfiguration, id, ignore);
static string GetIntelligentId(MetadataConfiguration metadataConfiguration, long id, bool ignore) => static string GetIntelligentId(MetadataConfiguration metadataConfiguration, long id, bool ignore) =>

View File

@ -1,15 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record Thing(
[property: JsonPropertyName("count")] int Count,
[property: JsonPropertyName("match")] string Match,
[property: JsonPropertyName("searchData")] SearchData SearchData
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(Thing))]
public partial class ThingGenerationContext : JsonSerializerContext
{
}

View File

@ -1,15 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record Time(
[property: JsonPropertyName("count")] int Count,
[property: JsonPropertyName("match")] string Match,
[property: JsonPropertyName("searchData")] SearchData SearchData
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(Time))]
public partial class TimeGenerationContext : JsonSerializerContext
{
}

View File

@ -1,15 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record Type(
[property: JsonPropertyName("count")] int Count,
[property: JsonPropertyName("match")] string Match,
[property: JsonPropertyName("searchData")] SearchData SearchData
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(Type))]
public partial class TypeGenerationContext : JsonSerializerContext
{
}

View File

@ -1,13 +0,0 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record XAccntParentMap(
);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(XAccntParentMap))]
public partial class XAccntParentMapGenerationContext : JsonSerializerContext
{
}