Skip to content

Commit

Permalink
Number of places (plan) calculations,
Browse files Browse the repository at this point in the history
render sequental order instead of pre-calculated position #18
  • Loading branch information
roman-yagodin committed Jul 8, 2021
1 parent 10b3806 commit e8b15e7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
26 changes: 25 additions & 1 deletion R7.Enrollment/Models/ConsolidatedCompetition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public class ConsolidatedCompetition: ICompetition

public int Plan => CalcPlanValue ();

public int PlanTarget => CalcPlanTargetValue ();

public int PlanSpecialRights => CalcPlanSpecialRightsValue ();

public IList<ConsolidatedEntrant> Entrants = new List<ConsolidatedEntrant> ();

public IList<Competition> Competitions { get; set; } = new List<Competition> ();
Expand All @@ -59,7 +63,27 @@ int CalcPlanValue ()
if (CompensationTypeBudget) {
return Competitions.Where (c => c.CompetitionTypeCode != (int) CompetitionType.NoExamCommon).Sum (c => c.Plan);
}
return Competitions.FirstOrDefault (c => c.CompetitionTypeCode == (int) CompetitionType.ByContract)?.Plan ?? -1;
return Competitions.FirstOrDefault ()?.Plan ?? -1;
}

int CalcPlanTargetValue ()
{
if (CompensationTypeBudget) {
return Competitions.FirstOrDefault (c => c.CompetitionTypeCode == (int) CompetitionType.Target)?.Plan ?? 0;
}

return -1;
}

int CalcPlanSpecialRightsValue ()
{
if (CompensationTypeBudget) {
return Competitions.FirstOrDefault (c => c.CompetitionTypeCode == (int) CompetitionType.SpecialRights)?.Plan ?? 0;
}

return -1;
}


}
}
35 changes: 30 additions & 5 deletions R7.Enrollment/Renderers/ConsolidatedRatingsHtmlRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,28 @@ public void RenderCompetition (ConsolidatedCompetition competition, XmlWriter ht
? (IComparer<ConsolidatedEntrant>) _entrantBudgetComparer
: (IComparer<ConsolidatedEntrant>) _entrantContractComparer;

foreach (var entrant in competition.Entrants.OrderBy (entr => entr, entrantComparer)) {
RenderEntrantTableRow (entrant, html);
var order = 1;
foreach (var entrant in competition.Entrants.OrderByDescending (entr => entr, entrantComparer)) {
RenderEntrantTableRow (entrant, html, order);
order++;
}

// end table
html.WriteEndElement ();
html.WriteEndElement ();

if (Settings.UseBasicCompetitionHeader) {
html.WriteElementString ("p",
$"Заявлений — {competition.Entrants.Count}, число мест — {competition.Plan}");
if (competition.CompensationTypeBudget) {
html.WriteElementString ("p",
$"Заявлений — {competition.Entrants.Count}, "
+ $"число мест — {competition.Plan}, из них: "
+ $"целевая квота — {competition.PlanTarget}, "
+ $"особая квота — {competition.PlanSpecialRights}");
}
else {
html.WriteElementString ("p",
$"Заявлений — {competition.Entrants.Count}, число мест — {competition.Plan}");
}
}
}

Expand All @@ -84,6 +95,13 @@ public void RenderEntrantsTableHeader (ICompetition competition, XmlWriter html)
html.WriteStartElement ("tr");
html.WriteElementWithAttributeString ("th", "№", "rowspan", "2");

#if DEBUG
html.WriteElementWithAttributeString ("td", "position", "rowspan", "2");
html.WriteElementWithAttributeString ("td", "absolutePosition", "rowspan", "2");
html.WriteElementWithAttributeString ("td", "commonRating", "rowspan", "2");
html.WriteElementWithAttributeString ("td", "agreedRating", "rowspan", "2");
#endif

if (Settings.Depersonalize) {
html.WriteElementWithAttributeString ("th", "Личный номер", "rowspan", "2");
}
Expand Down Expand Up @@ -115,7 +133,7 @@ public void RenderEntrantsTableHeader (ICompetition competition, XmlWriter html)
html.WriteEndElement ();
}

public void RenderEntrantTableRow (ConsolidatedEntrant entrant, XmlWriter html)
public void RenderEntrantTableRow (ConsolidatedEntrant entrant, XmlWriter html, int order)
{
html.WriteStartElement ("tr");

Expand All @@ -124,7 +142,14 @@ public void RenderEntrantTableRow (ConsolidatedEntrant entrant, XmlWriter html)
html.WriteAttributeString ("class", "enr-target-entrant-row");
}

html.WriteElementString ("td", order.ToString ());

#if DEBUG
html.WriteElementString ("td", entrant.Position.ToString ());
html.WriteElementString ("td", entrant.AbsolutePosition.ToString ());
html.WriteElementString ("td", entrant.CommonRating.ToString ());
html.WriteElementString ("td", entrant.AgreedRating.ToString ());
#endif

if (Settings.Depersonalize) {
html.WriteElementString ("td", entrant.PersonalNumber);
Expand Down

0 comments on commit e8b15e7

Please sign in to comment.