1.2.11.11 Golf Markers, Logs
This commit is contained in:
@@ -31,10 +31,17 @@ namespace Saxonite.Net.Core.Web.Base.Procs
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
public enum Task
|
||||
{
|
||||
CleanseCourseCaptions,
|
||||
}
|
||||
|
||||
public new class Config : SaxProcess_Web.Config
|
||||
{
|
||||
public Config(SaxSessionContext sessionContext, DbUpdateInfo dbUpdateInfo) : base(sessionContext, dbUpdateInfo)
|
||||
{ }
|
||||
/// <summary>Tasks to be run under this instance of the USGA Data Lookup process.</summary>
|
||||
public HashSet<Task> Tasks { get; } = new HashSet<Task>();
|
||||
}
|
||||
|
||||
public class CountryProvinceCodes
|
||||
@@ -154,6 +161,18 @@ namespace Saxonite.Net.Core.Web.Base.Procs
|
||||
// Run the process.
|
||||
protected override bool Run()
|
||||
{
|
||||
// Execute selected tasks.
|
||||
foreach (Task task in config.Tasks)
|
||||
{
|
||||
switch (task)
|
||||
{
|
||||
case Task.CleanseCourseCaptions:
|
||||
CleanseCourseCaptions();
|
||||
break;
|
||||
}
|
||||
if (!OK) break;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -636,26 +655,37 @@ namespace Saxonite.Net.Core.Web.Base.Procs
|
||||
/// </summary>
|
||||
/// <param name="course"></param>
|
||||
private void SetCourseCaption(CourseData course)
|
||||
{
|
||||
course.Caption = GetCourseCaption(course.FacilityName, course.CourseName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Combine facility and course names as required to generate course caption.
|
||||
/// <para>- NB Course name is sufficient if same as facility name.</para>
|
||||
/// </summary>
|
||||
/// <param name="course"></param>
|
||||
private String GetCourseCaption(String facilityName, String courseName)
|
||||
{
|
||||
// Facility (club) name.
|
||||
// - Strip id in brackets + anything following and remove generic phrases (golf club, hotel etc).
|
||||
String facilityName = CleanseFacilityName(Regex.Replace(course.FacilityName, "\\s*\\(\\s*\\d+\\s*\\).*$", ""));
|
||||
facilityName = CleanseFacilityName(Regex.Replace(facilityName, "\\s*\\(\\s*\\d+\\s*\\).*$", ""));
|
||||
// Course name.
|
||||
// - Remove id in brackets (occasionally found).
|
||||
// - Remove generic phrases (including for facility name).
|
||||
String courseName = CleanseCourseName(Regex.Replace(course.CourseName, "\\(\\s*\\d+\\s*\\)", ""));
|
||||
course.Caption = courseName;
|
||||
courseName = CleanseCourseName(Regex.Replace(courseName, "\\(\\s*\\d+\\s*\\)", ""));
|
||||
String courseCaption = courseName;
|
||||
if (!CourseNameMatchesFacility(facilityName, courseName))
|
||||
course.Caption = facilityName + " - " + courseName;
|
||||
courseCaption = facilityName + " - " + courseName;
|
||||
return courseCaption;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleanse Facility name by removing generic phrases, eg. golf club, hotel etc.
|
||||
/// </summary>
|
||||
public static String CleanseFacilityName(String facilityName)
|
||||
private String CleanseFacilityName(String facilityName)
|
||||
{
|
||||
facilityName = Regex.Replace(facilityName, "Hotel(,\\s*Golf)?\\s*(and|&)\\s*(Golf|Country|Sailing|Spa)(\\s*Club)?", "", RegexOptions.IgnoreCase);
|
||||
facilityName = Regex.Replace(facilityName, "Golf(\\s*Club)?\\s*(and|&)\\s*(Hotel|Country|Sailing|Spa)\\s*Club", "", RegexOptions.IgnoreCase);
|
||||
facilityName = Regex.Replace(facilityName, "Hotel(,\\s*Golf)?\\s*(and|&)\\s*(Golf|Country|Health|Sailing|Spa)(\\s*Club)?", "", RegexOptions.IgnoreCase);
|
||||
facilityName = Regex.Replace(facilityName, "Golf(\\s*Club)?\\s*(and|&)\\s*(Hotel|Country|Fitness|Sailing|Spa)(\\s*Club)", "", RegexOptions.IgnoreCase);
|
||||
facilityName = Regex.Replace(facilityName, "Golf\\s*(Club|Course|Links|Centre|Academy|Resort|Klub)(\\s*(Ltd|Limited))?", "", RegexOptions.IgnoreCase);
|
||||
facilityName = Regex.Replace(facilityName, "Club\\s*de\\s*Golf", "", RegexOptions.IgnoreCase);
|
||||
facilityName = Regex.Replace(facilityName, "\\s*(Golf|Country\\s*Club|Club|Ltd)\\s*$", "", RegexOptions.IgnoreCase);
|
||||
@@ -684,6 +714,93 @@ namespace Saxonite.Net.Core.Web.Base.Procs
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
public bool CleanseCourseCaptions()
|
||||
{
|
||||
SaLogger.Info($"{SysUtil.Fn} START", true);
|
||||
DateTime startedAt = DateTime.Now;
|
||||
ClearProcessMessages();
|
||||
|
||||
int courseCount = 0;
|
||||
int maxCourses = 0;
|
||||
int courseCaptionsCorrected = 0;
|
||||
|
||||
// Verify Course captions.
|
||||
using (DisposableCollection<SacsDisposable> disposables = new DisposableCollection<SacsDisposable>())
|
||||
{
|
||||
// Local function to allow break/return from within nested loop.
|
||||
void CompareCourseCaptions()
|
||||
{
|
||||
// Countries.
|
||||
foreach (SaxGolfUsgaCountry country in ReferenceGolfMgr.GetUsgaCountryList(new SaxGolfUsgaCountry.Params()))
|
||||
{
|
||||
disposables.Add(country);
|
||||
|
||||
// Provinces.
|
||||
SaxGolfUsgaProvince.Params prmProvince = new SaxGolfUsgaProvince.Params();
|
||||
prmProvince.CountryIdsIncluded.Add(country.Id);
|
||||
foreach (SaxGolfUsgaProvince province in ReferenceGolfMgr.GetUsgaProvinceList(prmProvince))
|
||||
{
|
||||
disposables.Add(province);
|
||||
|
||||
// Separate disposables for each province to restrict volume handled on each disposal.
|
||||
using (DisposableCollection<SacsDisposable> disposablesProvince = new DisposableCollection<SacsDisposable>())
|
||||
{
|
||||
|
||||
// Facilities.
|
||||
SaxGolfUsgaFacility.Params prmFacility = new SaxGolfUsgaFacility.Params();
|
||||
prmFacility.ProvinceIdsIncluded.Add(province.Id);
|
||||
foreach (SaxGolfUsgaFacility facility in ReferenceGolfMgr.GetUsgaFacilityList(prmFacility))
|
||||
{
|
||||
disposablesProvince.Add(facility);
|
||||
|
||||
// Courses.
|
||||
SaxGolfUsgaCourse.Params prmCourse = new SaxGolfUsgaCourse.Params();
|
||||
prmCourse.FacilityIdsIncluded.Add(facility.Id);
|
||||
foreach (SaxGolfUsgaCourse course in ReferenceGolfMgr.GetUsgaCourseList(prmCourse))
|
||||
{
|
||||
disposablesProvince.Add(course);
|
||||
courseCount++;
|
||||
|
||||
// Compare course caption.
|
||||
String courseCaption = GetCourseCaption(facility.FacilityName, course.CourseName);
|
||||
if (!course.Caption.Equals(courseCaption))
|
||||
{
|
||||
course.Caption = courseCaption;
|
||||
if (ReferenceGolfMgr.UpdateUsgaCourse(course, DbUpdateInfo))
|
||||
{
|
||||
courseCaptionsCorrected++;
|
||||
SaLogger.Info($"{SysUtil.Fn} Course caption corrected. Found: {course.Caption}.Corrected: {courseCaption}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Error updating Course caption: {ReferenceGolfMgr.ErrorStateMessage}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxCourses > 0 && courseCount > maxCourses)
|
||||
{
|
||||
SaLogger.Info($"{SysUtil.Fn} Maximum number of courses processed ({maxCourses}).");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Invoke local function.
|
||||
CompareCourseCaptions();
|
||||
}
|
||||
|
||||
// Log statistics.
|
||||
SaLogger.Info($"{SysUtil.Fn} Course caption corrected: {courseCaptionsCorrected}. Courses checked: {courseCount}.", true);
|
||||
|
||||
SaLogger.Info($"{SysUtil.Fn} END Elapsed: {DateUtil.FormatNumberOfSeconds((DateTime.Now - startedAt).TotalSeconds)}", true);
|
||||
return OK;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Identify the column for each marker property.
|
||||
|
||||
Reference in New Issue
Block a user