This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -54,7 +54,7 @@
|
||||
"AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles",
|
||||
"AYANOVA_FOLDER_TEMPORARY_SERVER_FILES": "c:\\temp\\RavenTestData\\tempfiles",
|
||||
"AYANOVA_SERVER_TEST_MODE": "true",
|
||||
"AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small",
|
||||
"AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "huge",
|
||||
"AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-7",
|
||||
"AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_13\\bin\\"
|
||||
},
|
||||
|
||||
@@ -214,6 +214,12 @@ namespace AyaNova.Biz
|
||||
.AddText(obj.Text2)
|
||||
.AddText(obj.Text3)
|
||||
.AddText(obj.Text4)
|
||||
.AddText(obj.Address)
|
||||
.AddText(obj.City)
|
||||
.AddText(obj.Region)
|
||||
.AddText(obj.Country)
|
||||
.AddText(obj.Latitude)
|
||||
.AddText(obj.Longitude)
|
||||
.AddCustomFields(obj.CustomFields);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,14 @@ namespace AyaNova.Models
|
||||
public string Text3 { get; set; }
|
||||
public string Text4 { get; set; }
|
||||
|
||||
//PHYSICAL ADDRESS
|
||||
public string Address { get; set; }
|
||||
public string City { get; set; }
|
||||
public string Region { get; set; }
|
||||
public string Country { get; set; }
|
||||
public decimal? Latitude { get; set; }
|
||||
public decimal? Longitude { get; set; }
|
||||
|
||||
public Unit()
|
||||
{
|
||||
Tags = new List<string>();
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace AyaNova.Util
|
||||
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
|
||||
private const int DESIRED_SCHEMA_LEVEL = 15;
|
||||
|
||||
internal const long EXPECTED_COLUMN_COUNT = 614;
|
||||
internal const long EXPECTED_COLUMN_COUNT = 620;
|
||||
internal const long EXPECTED_INDEX_COUNT = 175;
|
||||
|
||||
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
|
||||
@@ -731,7 +731,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
||||
"unitmodelid bigint null references aunitmodel(id), unithasownaddress bool, boughthere bool, purchasedfromvendorid bigint null references avendor(id), " +
|
||||
"receipt text null, purchaseddate timestamp null, description text null, replacedbyunitid bigint null references aunit(id), " +
|
||||
"overridemodelwarranty bool, warrantylength integer null, warrantyterms text null, usesbanking bool, metered bool, lifetimewarranty bool, " +
|
||||
"text1 text null, text2 text null, text3 text null, text4 text null, " +
|
||||
"text1 text null, text2 text null, text3 text null, text4 text null, address text null, city text null, region text null, country text null, latitude decimal(8,6) null, longitude decimal(9,6) null, " +
|
||||
"CONSTRAINT UNQ_UnitSerialModelId UNIQUE (serial, unitmodelid) " +
|
||||
" )");
|
||||
|
||||
|
||||
@@ -241,6 +241,9 @@ namespace AyaNova.Util
|
||||
//UNITMODELS
|
||||
await SeedUnitModelAsync(log, 10);
|
||||
|
||||
//UNITS
|
||||
await SeedUnitAsync(log, 500);//5 times the customers or 5 units per customer
|
||||
|
||||
|
||||
//PERF
|
||||
watch.Stop();
|
||||
@@ -313,6 +316,10 @@ namespace AyaNova.Util
|
||||
//UNITMODELS
|
||||
await SeedUnitModelAsync(log, 25);
|
||||
|
||||
|
||||
//UNITS
|
||||
await SeedUnitAsync(log, 2500);//5 times the customers or 5 units per customer
|
||||
|
||||
//PERF
|
||||
watch.Stop();
|
||||
await LogStatusAsync(JobId, LogJob, log, $"MEDIUM level sample data seeded in {watch.ElapsedMilliseconds} ms");
|
||||
@@ -397,6 +404,10 @@ namespace AyaNova.Util
|
||||
//UNITMODELS
|
||||
await SeedUnitModelAsync(log, 30);
|
||||
|
||||
|
||||
//UNITS
|
||||
await SeedUnitAsync(log, 25000);//5 times the customers or 5 units per customer
|
||||
|
||||
//PERF
|
||||
watch.Stop();
|
||||
await LogStatusAsync(JobId, LogJob, log, $"LARGE level sample data seeded in {watch.ElapsedMilliseconds} ms");
|
||||
@@ -480,6 +491,9 @@ namespace AyaNova.Util
|
||||
|
||||
//UNITMODELS
|
||||
await SeedUnitModelAsync(log, 40);
|
||||
|
||||
//UNITS
|
||||
await SeedUnitAsync(log, 100000);//5 times the customers or 5 units per customer
|
||||
|
||||
//PERF
|
||||
watch.Stop();
|
||||
@@ -870,7 +884,7 @@ namespace AyaNova.Util
|
||||
|
||||
|
||||
public HashSet<string> HashUserNames = new HashSet<string>();
|
||||
private int TotalSeededUserCount = 0;
|
||||
private int TotalSeededUsers = 0;
|
||||
|
||||
public async Task SeedUserAsync(
|
||||
ILogger log, int count, AuthorizationRoles roles, UserType userType,
|
||||
@@ -910,7 +924,7 @@ namespace AyaNova.Util
|
||||
u.Password = u.Login;
|
||||
u.Roles = roles;
|
||||
u.UserType = userType;
|
||||
u.EmployeeNumber = "A-" + (454 + TotalSeededUserCount + x).ToString() + "-Y";
|
||||
u.EmployeeNumber = "A-" + (454 + TotalSeededUsers + x).ToString() + "-Y";
|
||||
u.Notes = Fake.Lorem.Sentence(null, 5);//Fake.Lorem.Paragraph(2);
|
||||
//TODO: After have USER and HEADOFFICE and VENDOR, if usertype is subcontractor or client or headoffice it needs to set a corresponding user's parent org record id to go with it
|
||||
//use provided tags or generate them
|
||||
@@ -940,7 +954,7 @@ namespace AyaNova.Util
|
||||
{
|
||||
UserBiz biz = UserBiz.GetBiz(ct);
|
||||
var NewObject = await biz.CreateAsync(u);
|
||||
TotalSeededUserCount++;
|
||||
TotalSeededUsers++;
|
||||
if (NewObject == null)
|
||||
{
|
||||
log.LogError($"Seeder::SeedUser error creating {u.Name}\r\n" + biz.GetErrorsAsString());
|
||||
@@ -982,7 +996,7 @@ namespace AyaNova.Util
|
||||
o.UserType = randomUserType;
|
||||
o.Notes = Fake.Lorem.Sentence(null, 5);
|
||||
o.Tags = RandomTags();
|
||||
o.UserId = Fake.Random.Int(1, TotalSeededUserCount);
|
||||
o.UserId = Fake.Random.Int(1, TotalSeededUsers);
|
||||
|
||||
//RANDOM CUSTOM FIELD DATA
|
||||
var c1 = DateUtil.UniversalISO8661Format(Fake.Date.Between(DateTime.Now.AddYears(-1), DateTime.Now.AddYears(1)));
|
||||
@@ -1010,7 +1024,7 @@ namespace AyaNova.Util
|
||||
|
||||
public HashSet<string> HashCompanyNames = new HashSet<string>();
|
||||
|
||||
private int TotalSeededCustomers=0;
|
||||
private int TotalSeededCustomers = 0;
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
//CUSTOMER
|
||||
@@ -1076,7 +1090,7 @@ private int TotalSeededCustomers=0;
|
||||
}
|
||||
|
||||
|
||||
private int TotalSeededHeadOffices=
|
||||
private int TotalSeededHeadOffices = 0;
|
||||
//////////////////////////////////////////////////////
|
||||
//HEADOFFICE
|
||||
//
|
||||
@@ -1118,7 +1132,7 @@ private int TotalSeededHeadOffices=
|
||||
{
|
||||
HeadOfficeBiz biz = HeadOfficeBiz.GetBiz(ct);
|
||||
var NewObject = await biz.CreateAsync(o);
|
||||
|
||||
TotalSeededHeadOffices++;
|
||||
if (NewObject == null)
|
||||
{
|
||||
var err = $"Seeder::SeedHeadOffice error creating {o.Name}\r\n{biz.GetErrorsAsString()}";
|
||||
@@ -1135,7 +1149,7 @@ private int TotalSeededHeadOffices=
|
||||
}
|
||||
|
||||
|
||||
|
||||
private int TotalSeededVendors = 0;
|
||||
//////////////////////////////////////////////////////
|
||||
//VENDOR
|
||||
//
|
||||
@@ -1176,7 +1190,7 @@ private int TotalSeededHeadOffices=
|
||||
{
|
||||
VendorBiz biz = VendorBiz.GetBiz(ct);
|
||||
var NewObject = await biz.CreateAsync(o);
|
||||
|
||||
TotalSeededVendors++;
|
||||
if (NewObject == null)
|
||||
{
|
||||
var err = $"Seeder::SeedVendor error creating {o.Name}\r\n{biz.GetErrorsAsString()}";
|
||||
@@ -1191,7 +1205,7 @@ private int TotalSeededHeadOffices=
|
||||
|
||||
|
||||
public HashSet<string> HashProjectNames = new HashSet<string>();
|
||||
|
||||
private int TotalSeededProjects = 0;
|
||||
//////////////////////////////////////////////////////
|
||||
//PROJECT
|
||||
//
|
||||
@@ -1215,7 +1229,7 @@ private int TotalSeededHeadOffices=
|
||||
o.DateStarted = dtSeed;
|
||||
if (Fake.Random.Number(9) != 5)
|
||||
o.DateCompleted = dtSeed.AddDays(Fake.Random.Long(2, 100));
|
||||
o.ProjectOverseerId = Fake.Random.Long(2, 13);
|
||||
o.ProjectOverseerId = Fake.Random.Long(2, 13);//NOTE: this is exactly 13 not total seeded users because it needs to be inside users and they're seeded first
|
||||
|
||||
|
||||
//This seems wrong to do in a loop but is 4 times faster this way ?!?
|
||||
@@ -1223,7 +1237,7 @@ private int TotalSeededHeadOffices=
|
||||
{
|
||||
ProjectBiz biz = ProjectBiz.GetBiz(ct);
|
||||
var NewObject = await biz.CreateAsync(o);
|
||||
|
||||
TotalSeededProjects++;
|
||||
if (NewObject == null)
|
||||
{
|
||||
var err = $"Seeder::SeedProject error creating {o.Name}\r\n{biz.GetErrorsAsString()}";
|
||||
@@ -1351,7 +1365,7 @@ private int TotalSeededHeadOffices=
|
||||
o.Active = true;
|
||||
o.Notes = Fake.Lorem.Sentence();
|
||||
o.Tags = RandomTags();
|
||||
o.VendorId = Fake.Random.Long(1, 10);
|
||||
o.VendorId = Fake.Random.Long(1, TotalSeededVendors);//random picks in range Inclusive but sql id's start at 1 so this is kosher (not zero based)
|
||||
o.UPC = Fake.Commerce.Ean13();
|
||||
o.LifeTimeWarranty = false;
|
||||
o.IntroducedDate = Fake.Date.Between(seedStartWindow, DateTime.Now).ToUniversalTime();
|
||||
@@ -1378,12 +1392,13 @@ private int TotalSeededHeadOffices=
|
||||
|
||||
|
||||
public HashSet<string> HashUnitNames = new HashSet<string>();
|
||||
private int TotalSeededUnits = 0;
|
||||
//////////////////////////////////////////////////////
|
||||
//UNIT
|
||||
//
|
||||
public async Task SeedUnitAsync(ILogger log, int count)
|
||||
{
|
||||
DateTime seedStartWindow = DateTime.Now.AddYears(-5);
|
||||
DateTime seedStartWindow = DateTime.Now.AddYears(-10);
|
||||
DateTime seedEndWindow = DateTime.Now.AddYears(1);
|
||||
var WarrantyMonths = new[] { 1, 6, 12, 24, 36 };
|
||||
var WarrantyTerms = new[] { "Parts only", "Parts and service", "Service only", "Shipping parts and service", "First month parts and service here; after is depot only" };
|
||||
@@ -1394,35 +1409,69 @@ private int TotalSeededHeadOffices=
|
||||
|
||||
do
|
||||
{
|
||||
o.Name = $"{Fake.Vehicle.Model()} {Fake.Commerce.Categories(1)[0]}";
|
||||
} while (!HashUnitModelNames.Add(o.Name));
|
||||
|
||||
do
|
||||
{
|
||||
o.Number = Fake.Finance.Account(6);
|
||||
} while (!HashUnitModelNames.Add(o.Number));
|
||||
o.Serial = Fake.Finance.Account();
|
||||
} while (!HashUnitNames.Add(o.Serial));
|
||||
|
||||
o.Active = true;
|
||||
o.Notes = Fake.Lorem.Sentence();
|
||||
o.Tags = RandomTags();
|
||||
o.VendorId = Fake.Random.Long(1, 10);
|
||||
o.UPC = Fake.Commerce.Ean13();
|
||||
o.LifeTimeWarranty = false;
|
||||
o.IntroducedDate = Fake.Date.Between(seedStartWindow, DateTime.Now).ToUniversalTime();
|
||||
o.Discontinued = false;
|
||||
o.DiscontinuedDate = null;
|
||||
o.WarrantyLength = Fake.PickRandom(WarrantyMonths);
|
||||
o.WarrantyTerms = Fake.PickRandom(WarrantyTerms);
|
||||
//Override model warranty 5% chance (1/20)
|
||||
if (Fake.Random.Number(1, 20) == 5)
|
||||
{
|
||||
o.OverrideModelWarranty = true;
|
||||
o.LifeTimeWarranty = false;
|
||||
o.WarrantyLength = Fake.PickRandom(WarrantyMonths);
|
||||
o.WarrantyTerms = Fake.PickRandom(WarrantyTerms);
|
||||
}
|
||||
|
||||
o.CustomerId = Fake.Random.Long(1, TotalSeededCustomers);
|
||||
o.UnitModelId = Fake.Random.Long(1, TotalSeededUnitModels);
|
||||
o.BoughtHere = true;
|
||||
|
||||
//Unit bought elsewhere 10% chance (1/10)
|
||||
if (Fake.Random.Number(1, 10) == 5)
|
||||
{
|
||||
o.BoughtHere = false;
|
||||
o.PurchasedFromVendorId = Fake.Random.Long(1, TotalSeededVendors);
|
||||
}
|
||||
|
||||
o.Receipt=Fake.Finance.Account(6);
|
||||
o.PurchasedDate=Fake.Date.Between(seedStartWindow, DateTime.Now).ToUniversalTime();
|
||||
o.Description=Fake.Commerce.ProductName();
|
||||
o.ReplacedByUnitId=null;
|
||||
//for now no banked units in seeds
|
||||
o.UsesBanking=false;
|
||||
o.Metered=false;//for now no meters either
|
||||
o.Text1=null;
|
||||
o.Text2=null;
|
||||
o.Text3=null;
|
||||
o.Text4=null;
|
||||
|
||||
//Unit has own address 5% chance (1/20)
|
||||
if (Fake.Random.Number(1, 20) == 5)
|
||||
{
|
||||
o.UnitHasOwnAddress = true;
|
||||
o.Latitude = (decimal)Fake.Address.Latitude();
|
||||
o.Longitude = (decimal)Fake.Address.Longitude();
|
||||
o.Address = Fake.Address.StreetAddress();
|
||||
o.City = Fake.Address.City();
|
||||
o.Region = Fake.Address.State();
|
||||
o.Country = Fake.Address.Country();
|
||||
}
|
||||
else
|
||||
{
|
||||
o.UnitHasOwnAddress = false;
|
||||
}
|
||||
|
||||
//This seems wrong to do in a loop but is 4 times faster this way ?!?
|
||||
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||
{
|
||||
UnitModelBiz biz = UnitModelBiz.GetBiz(ct);
|
||||
UnitBiz biz = UnitBiz.GetBiz(ct);
|
||||
var NewObject = await biz.CreateAsync(o);
|
||||
|
||||
TotalSeededUnits++;
|
||||
if (NewObject == null)
|
||||
{
|
||||
var err = $"Seeder::SeedUnitModel error creating {o.Name}\r\n{biz.GetErrorsAsString()}";
|
||||
var err = $"Seeder::SeedUnit error creating {o.Serial}\r\n{biz.GetErrorsAsString()}";
|
||||
log.LogError(err);
|
||||
throw new System.Exception(err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user