Skip to content

Commit

Permalink
Restored the original calculations of age and lifetime, the dependenc…
Browse files Browse the repository at this point in the history
…e of age on the use of the Time Line plugin (fix #503)
  • Loading branch information
Serg-Norseman committed Dec 15, 2023
1 parent 4c53d2f commit 71cbbea
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 10 deletions.
1 change: 1 addition & 0 deletions locales/help_enu/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Change log</h1>

<p>
<b>??.??.2024 [v2.29.0 &amp; v3.5.0]</b><ul>
<li>Restored the original mode for calculating age and lifetime, the dependence of age on the use of the Time Line plugin.
<li>Added the feature to add multiple people in the photo viewing window.
<li>Restored the possibility of empty value of residence facts.
<li>Added localization to Japanese [Takashi Namba (難波鷹史)].
Expand Down
5 changes: 5 additions & 0 deletions locales/help_rus/gkhDateSpecials.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ <h1>Особенности работы с датами</h1>
как признак.
</p>

<hr />
<p>
Внимание: при использовании плагина "Линия времени" колонка возраста показывает значение, расчетное к заданному году.
</p>

<hr />
<p>Также смотрите: <a href="gkhRec_Event.html">События</a>.</p>

Expand Down
1 change: 1 addition & 0 deletions locales/help_rus/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>История версий</h1>

<p>
<b>??.??.2024 [v2.29.0 &amp; v3.5.0]</b><ul>
<li>Восстановлен оригинальный режим расчета возраста и продолжительности жизни, зависимости возраста от использования плагина "Линия времени".
<li>Добавлена возможность присоединять ряд персон в окне просмотра фотографий.
<li>Восстановлена возможность пустого значения фактов местожительства.
<li>Добавлена локализация на японский язык [Takashi Namba (難波鷹史)].
Expand Down
11 changes: 9 additions & 2 deletions locales/help_rus/gkhSvc_TimeLine.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ <h1>Линия времени</h1>

<p>
Линия времени - наглядный инструмент фильтрации базы данных. Когда меняется положение бегунка, задающего год - все <a href="gkhRec_Individual.html">персональные записи</a>
фильтруются так, чтобы в списке отображались только жившие на этот год люди. Также в этом режиме колонка возраста показывает значение,
расчетное к заданному году.
фильтруются так, чтобы в списке отображались только жившие на этот год люди.
</p>

<p>
Инструмент полезен для анализа данных и при обработке источников - чтобы в любой момент времени видеть только тех, кто реально должен был быть
жив в обрабатываемый год. Инструмент может использоваться одновременно с обычной фильтрацией персон по местам и именам.
</p>

<hr />
<p>
Внимание: в этом режиме колонка возраста показывает значение, расчетное к заданному году.
</p>

<hr />
<p>Также смотрите: <a href="gkhDateSpecials.html">Особенности работы с датами</a>.</p>

</body>
</html>
37 changes: 31 additions & 6 deletions projects/GKCore/GKCore/GKUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
using GKCore.Cultures;
using GKCore.Import;
using GKCore.Interfaces;
using GKCore.Lists;
using GKCore.Options;
using GKCore.Types;
using UtfUnknown;
Expand Down Expand Up @@ -1083,7 +1084,14 @@ public static int GetChronologicalYear(GDMCustomEvent evt)
return (evt == null) ? 0 : evt.Date.GetChronologicalYear();
}

public static int GetEventsYearsDiff(GDMCustomEvent ev1, GDMCustomEvent ev2, bool currentEnd)
/// <summary>
/// Calculate the difference in years between two dates.
/// </summary>
/// <param name="ev1">Starting event.</param>
/// <param name="ev2">End event.</param>
/// <param name="inference">If the 'inference' argument is given, then if there is no end date, it is possible to use the current year.</param>
/// <returns></returns>
public static int GetEventsYearsDiff(GDMCustomEvent ev1, GDMCustomEvent ev2, bool inference)
{
int result = -1;

Expand All @@ -1101,13 +1109,20 @@ public static int GetEventsYearsDiff(GDMCustomEvent ev1, GDMCustomEvent ev2, boo
}
#else
var udn1 = (ev1 == null) ? UDN.CreateUnknown() : ev1.Date.GetUDN();
var udn2 = (ev2 == null) ? UDN.CreateUnknown() : ev2.Date.GetUDN();

DateTime dt2 = (currentEnd || !udn2.HasKnownYear()) ? DateTime.Now : udn2.GetGregorianDateTime();

if (udn1.HasKnownYear()) {
DateTime dt1 = udn1.GetGregorianDateTime();
result = GetDifferenceInYears(dt1, dt2);

var udn2 = (ev2 == null) ? UDN.CreateUnknown() : ev2.Date.GetUDN();
DateTime dt2;
if (udn2.HasKnownYear()) {
dt2 = udn2.GetGregorianDateTime();
result = GetDifferenceInYears(dt1, dt2);
} else {
if (inference) {
dt2 = DateTime.Now;
result = GetDifferenceInYears(dt1, dt2);
}
}
}
#endif
} catch (Exception ex) {
Expand Down Expand Up @@ -3626,6 +3641,16 @@ public static void SetBaseExternalFilter(IBaseWindow baseWindow, FilterLifeMode
}
}

public static void SetTimeLineYear(IBaseWindow baseWindow, int year)
{
if (baseWindow != null) {
IRecordsListModel listMan = baseWindow.GetRecordsListManByType(GDMRecordType.rtIndividual);
if (listMan != null) {
((IndividualListFilter)listMan.Filter).TimeLineYear = year;
}
}
}

public static void CollectTimeLineData(IBaseWindow baseWindow, out int yearMin, out int yearMax)
{
yearMin = 10000;
Expand Down
6 changes: 5 additions & 1 deletion projects/GKCore/GKCore/Lists/IndividualListModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public sealed class IndividualListFilter : ListFilter, IIndividualListFilter
public FilterGroupMode SourceMode;
public string SourceRef;
public string EventVal;
public int TimeLineYear;

public FilterLifeMode FilterLifeMode { get; set; }

Expand All @@ -80,6 +81,7 @@ public override void Clear()
SourceMode = FilterGroupMode.All;
SourceRef = "";
EventVal = "*";
TimeLineYear = -1;
}

public override string ToString(IListSource listSource)
Expand Down Expand Up @@ -144,6 +146,7 @@ public override void Assign(IListFilter other)
SourceMode = otherFilter.SourceMode;
SourceRef = otherFilter.SourceRef;
EventVal = otherFilter.EventVal;
TimeLineYear = otherFilter.TimeLineYear;
}

public override void Deserialize(string value)
Expand Down Expand Up @@ -484,7 +487,8 @@ protected override object GetColumnValueEx(int colType, int colSubtype, bool isV
break;

case ColumnType.ctAge:
result = (isVisible) ? (object)GKUtils.GetAgeStr(fFetchedRec, -1) : GKUtils.GetAge(fFetchedRec, -1);
int tlYear = ((IndividualListFilter)fFilter).TimeLineYear;
result = (isVisible) ? (object)GKUtils.GetAgeStr(fFetchedRec, tlYear) : GKUtils.GetAge(fFetchedRec, tlYear);
break;

case ColumnType.ctLifeExpectancy:
Expand Down
4 changes: 3 additions & 1 deletion projects/plugins/GKTimeLinePlugin/TimeLineWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ private void tbTimeLine_ValueChanged(object sender, EventArgs e)
{
if (fBase != null) {
fYearCurrent = tbTimeLine.Value;
GKUtils.SetTimeLineYear(fBase, fYearCurrent);
fBase.ApplyFilter(GDMRecordType.rtIndividual);
}
UpdateStatus();
Expand All @@ -105,11 +106,12 @@ public void BaseChanged(IBaseWindow baseWin)
{
if (fBase != baseWin) {
// restore filter's default state
fYearCurrent = -1;
GKUtils.SetTimeLineYear(fBase, fYearCurrent);
GKUtils.SetBaseExternalFilter(fBase, FilterLifeMode.lmAll, null);

// initialize data
fBase = baseWin;
fYearCurrent = -1;
GKUtils.CollectTimeLineData(fBase, out fYearMin, out fYearMax);

// set new filter parameters
Expand Down

0 comments on commit 71cbbea

Please sign in to comment.