Skip to content

Commit 4897ca9

Browse files
public version works, show data without non-full available years for unstandardized #53
1 parent 1120818 commit 4897ca9

4 files changed

Lines changed: 77 additions & 17 deletions

File tree

Controllers/LUICalculationController.cs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,21 @@ public ActionResult Index()
4646
// set page title
4747
ViewBag.Title = PresentationModel.GetViewTitleForTenant(TITLE, this.Session.GetTenant());
4848

49+
4950
//create model
5051
LUIQueryModel model = new LUIQueryModel();
5152
model.MissingComponentData = DataAccess.GetMissingComponentData(GetServerInformation());
53+
54+
//check if public access
55+
long.TryParse(this.User.Identity.GetUserId(), out long userId);
56+
57+
//no bexis user == public access and id uncomplete data exsits
58+
if(userId == 0 && model.MissingComponentData.Count() > 0)
59+
{
60+
model.IsPublicAccess = true;
61+
}
62+
63+
5264
model.NewComponentsSetDatasetId = Models.Settings.get("lui:datasetNewComponentsSet").ToString();
5365
var datasetInfo = DataAccess.GetDatasetInfo(model.NewComponentsSetDatasetId, GetServerInformation());
5466
model.NewComponentsSetDatasetVersion = DataAccess.GetDatasetInfo(model.NewComponentsSetDatasetId, GetServerInformation()).Version;
@@ -66,15 +78,31 @@ public ActionResult Index()
6678
}
6779
}
6880

69-
public ActionResult ShowPrimaryData(long datasetID)
81+
public ActionResult ShowPrimaryData(long datasetID, bool isPublicAccess)
7082
{
7183
LUIQueryModel lUIQueryModel = new LUIQueryModel();
7284
lUIQueryModel.RawVsCalc.SelectedValue = "unstandardized";
7385
lUIQueryModel.DownloadDatasetId = datasetID.ToString();
7486
Session["LUICalModel"] = lUIQueryModel;
7587

7688
DataModel model = new DataModel();
77-
model.Data = DataAccess.GetComponentData(datasetID.ToString(), GetServerInformation());
89+
DataTable data = DataAccess.GetComponentData(datasetID.ToString(), GetServerInformation());
90+
if (isPublicAccess)
91+
{
92+
//remove not complete years data for non public access
93+
var missingData = DataAccess.GetMissingComponentData(GetServerInformation());
94+
if (missingData.Count > 0)
95+
{
96+
List<string> incompleteYears = missingData.Select(x => x.Year).Distinct().ToList();
97+
RemoveNotComplateYears(data, incompleteYears);
98+
model.Data = data;
99+
100+
}
101+
else
102+
model.Data = data;
103+
}
104+
else
105+
model.Data = data;
78106

79107
return PartialView("_data", model);
80108
}
@@ -122,6 +150,18 @@ public ActionResult CalculateLUI(LUIQueryModel model)
122150
break;
123151
}
124152
DataTable dt_sourceData = DataAccess.GetComponentData(dsId, GetServerInformation());
153+
if(model.IsPublicAccess)
154+
{
155+
//remove not complete years data for non public access
156+
var missingData = DataAccess.GetMissingComponentData(GetServerInformation());
157+
if (missingData.Count > 0)
158+
{
159+
List<string> incompleteYears = missingData.Select(x => x.Year).Distinct().ToList();
160+
RemoveNotComplateYears(dt_sourceData, incompleteYears);
161+
}
162+
163+
}
164+
125165
var results = CalculateLui.DoCalc(model, dt_sourceData);
126166

127167
DataModel dataModel = new DataModel();
@@ -361,6 +401,9 @@ private string GetUserToken()
361401
long userId = 0;
362402
long.TryParse(this.User.Identity.GetUserId(), out userId);
363403

404+
if(userId==0)
405+
return "";
406+
364407
var user = identityUserService.FindById(userId);
365408

366409
user = identityUserService.FindById(userId);
@@ -373,6 +416,15 @@ private string GetUserToken()
373416
userManager.Dispose();
374417
}
375418
}
419+
420+
private void RemoveNotComplateYears(DataTable data, List<string> years)
421+
{
422+
foreach (var year in years)
423+
{
424+
data.AsEnumerable().Where(r => r.Field<DateTime>("Year").ToString("yyyy") == year).ToList().ForEach(row => row.Delete());
425+
data.AcceptChanges();
426+
}
427+
}
376428
}
377429

378430
}

Models/LUIQueryModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class LUIQueryModel
2828

2929
public string NewComponentsSetLastUpdate { get; set; }
3030

31+
public bool IsPublicAccess { get; set; }
32+
3133

3234
public LUIQueryModel()
3335
{
@@ -40,6 +42,8 @@ public LUIQueryModel()
4042
Plotlevel = new RadioButtonControlHelper();
4143
ComponentsSet = new RadioButtonControlHelper();
4244

45+
IsPublicAccess = false;
46+
4347
MissingComponentData = new List<MissingComponentData>();
4448

4549
//fill ComponentsSet

Scripts/lui.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Setup XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
88

99
const $dataEl = $('#divQuery0'),
10-
datasetIdOld = $dataEl.data('datasetidold'),
10+
datasetIdOld = $dataEl.data('datasetidold'),
1111
datasetIdNew = $dataEl.data('datasetidnew'),
12-
versionIdOld = $dataEl.data('versionidold'),
13-
versionIdNew = $dataEl.data('versionidnew'),
14-
showdataUrl = $dataEl.data('showdataurl');
12+
showdataUrl = $dataEl.data('showdataurl'),
13+
isPublic = $dataEl.data('ispublic');
1514

16-
console.log($dataEl.data());
1715

1816
/* XXXXXXXXXXXXXXXXXXXXXXXXXX Event Handlers XXXXXXXXXXXXXXXXXXXXXXXXXXX */
1917

2018
var datasetId = datasetIdNew;
21-
var versionId= versionIdNew;
19+
console.log(isPublic);
20+
var isPublicAccess = isPublic.toLowerCase();
2221

2322
/* ------------------------------ Query 00 ------------------------------ */
2423

@@ -75,12 +74,14 @@
7574
// show complete dataset and leave wizzard steps hidden
7675
$('#divResultGrid').empty();
7776
$('#dtmLuiSpinner').show();
77+
console.log(isPublicAccess);
7878
$.ajax({
7979
method: 'get',
8080
url: showdataUrl,
8181
data: {
8282
datasetID: datasetId,
83-
versionId: versionId
83+
isPublicAccess: isPublicAccess
84+
8485
}
8586
})
8687
.done(function (data) {

Views/LUICalculation/Index.cshtml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@
1818
@Html.ActionLink("How to reference", "DownloadPDF", new { fileName = "LUI-citation.pdf" }, new { @class = "bx-button small function", target = "_blank" })
1919
@Html.ActionLink("How to use the tool", "DownloadPDF", new { fileName = "HowToPlusDiagram.pdf" }, new { @class = "bx-button small function", target = "_blank" })
2020
@Html.ActionLink("LUI changes docu", "DownloadPDF", new { fileName = "LuiChangesInfo.pdf" }, new { @class = "bx-button small function", target = "_blank" })
21-
@if (Model.MissingComponentData.Count() != 0)
21+
@if (Model.MissingComponentData.Count() != 0 && Model.IsPublicAccess == false)
2222
{
2323
<div class="dtm-divBox">
2424
<p class="dtm-para_green">Warning: Some input data needed for calculation is not completely available. Below you will find the affected years, and for which plots the data is missing. For this year, use the LUI just for testing purposes. For publications, use only LUI where no warning is given.</p>
2525

2626
<div class="dtm-controls">
27-
@if (Model.MissingComponentData.Count() == 0)
28-
{
29-
<div>No warnings.</div>
30-
}
31-
else
32-
{
27+
28+
@if (Model.MissingComponentData.Count() == 0)
29+
{
30+
<div>No warnings.</div>
31+
}
32+
else
33+
{
3334
<div class="box">
3435
<b>Source Dataset:</b> @Model.NewComponentsSetDatasetId<br />
3536
</div>
@@ -57,7 +58,8 @@
5758
</div>
5859

5960
}
60-
}
61+
}
62+
6163
</div>
6264

6365
<br />
@@ -81,6 +83,7 @@
8183
<div id="divQuery0" class="dtm-divBox"
8284
data-datasetidOld="@Settings.get("lui:datasetOldComponentsSet")"
8385
data-datasetidNew="@Settings.get("lui:datasetNewComponentsSet")"
86+
data-isPublic="@Model.IsPublicAccess"
8487
data-showdataurl="@Url.Action("ShowPrimaryData", "LUICalculation", new { Area = "LUI" })">
8588
<p class="dtm-para_green">Please select if you want to extract the raw data (unstandardized) OR if you want to calculate the LUI (standardized).</p>
8689
<div class="dtm-controls">

0 commit comments

Comments
 (0)