Skip to content

Commit

Permalink
add inspections report
Browse files Browse the repository at this point in the history
  • Loading branch information
tharlestsa committed Aug 11, 2023
1 parent 4c8c101 commit cb08f4f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/client/controllers/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Application.controller('dashboardController', function($rootScope, $scope, $loca
size: 18
}
};

console.log('pointsComplet',data.pointsComplet)
Plotly.newPlot(gd, chartPizza, layout, {displayModeBar: false});
chartsGd.push(gd);
});
Expand Down
8 changes: 8 additions & 0 deletions src/client/controllers/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ Application.controller('navController', function($rootScope, $scope, $location,
window.open('service/points/csv', '_blank')
};

$scope.downloadFinalReport = function() {
if($rootScope.campaignFinished){
window.open(`https://timeseries.lapig.iesa.ufg.br/api/analytics/tvi-indonesia/${$rootScope.user.campaign._id}/csv?direct=true`, '_blank')
} else {
$window.alert(`The campaign/login was not completed. There are still points to finish the inspections.`)
}
};

requester._get('login/user', function(result) {
$rootScope.user = result;
});
Expand Down
9 changes: 9 additions & 0 deletions src/client/controllers/supervisor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Application.controller('supervisorController', function ($rootScope, $scope, $lo
$scope.showChartsLandsat = false
$scope.showCorrectCampaign = false;
$scope.showloading = true;
$rootScope.campaignFinished
util.waitUserData(function () {
$scope.showloading = false;
$scope.size = 4;
Expand Down Expand Up @@ -637,6 +638,7 @@ Application.controller('supervisorController', function ($rootScope, $scope, $lo
initFormViewVariables();
//generateOptionYears($scope.config.initialYear, $scope.config.finalYear);
generateMaps();
getCampaignMatadata();
if (!$scope.isChaco) {
// createModisChart(data.point.dates);
// createLandsatChart();
Expand All @@ -657,6 +659,13 @@ Application.controller('supervisorController', function ($rootScope, $scope, $lo
$window.alert(data ? `Diperbaiki: Titik-titik ${data}` : 'Dengan perusahaan tanpa masalah dengan inspeksi.')
});
}
const getCampaignMatadata = () => {
$scope.showloading = true;
requester._get(`dashboard/points-inspection`, function (data) {
$scope.showloading = false;
$rootScope.campaignFinished = data.pointsComplet == 100;
});
}

$window.addEventListener("keydown", (event) => {
if (event.key !== undefined) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/views/navbar.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<div class="col-md-4" ng-show="user" style="float: left">
<h3><center><span style="color: #FFFFFF"> {{user.campaign._id}} </span></center></h3>
</div>
<div class="col-md-4 rightNavBar" style="float: right; margin-right: -22px; margin-top: 2px;">
<button type="button" class="btn btn-success" href="#" ng-click="downloadCSV()" style="color:white">Unduh CSV</button>
<div class="col-md-4" style="display: flex; justify-content: flex-end; align-items: center;">
<button type="button" class="btn btn-success" href="#" ng-click="downloadFinalReport()" style="color:white">Inspection Report</button>
<button type="button" class="btn btn-danger" href="#" ng-click="logoff()" style="color:white">Keluar</button>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/server/bin/correct_campaigns.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

while read -r campaign; do
# /APP/tvi/src/server/bin/correct_campaigns.log
# /APP/tvi/src/server/bin/correct_campaigns.log
echo "$(date) - Calling: $campaign" >> /APP/tvi/src/server/bin/correct_campaigns.log
# mongo tvi-indonesia --host 172.18.0.6 --eval 'var campaignId="'$campaign'";' correct_campaign.js > /dev/null 2>&1
#mongo tvi-indonesia --host 172.18.0.6 --eval 'var campaignId="'$campaign'";' correct_campaign.js > /dev/null 2>&1
mongo tvi-indonesia --host 172.18.0.6 --eval 'var campaignId="'$campaign'";' correct_campaign.js >> /APP/tvi/src/server/bin/correct_campaigns.log
done < "$1"
18 changes: 8 additions & 10 deletions src/server/controllers/supervisor.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,9 @@ module.exports = function (app) {
const initialYear = campaign.initialYear
const finalYear =campaign.finalYear

const colNames = ["id","lat","lon"]
const colNames = ["id", "lat", "lon"]

for(let i=0; i < nInspections; i++) {

colNames.push('user_' + (i+1))
colNames.push('time_' + (i+1))

Expand All @@ -584,41 +583,40 @@ module.exports = function (app) {
delimiter: ';'
});

const points = await pointsCollection.find({ 'campaign': campaign._id }).toArray()
const points = await pointsCollection.find({'campaign': campaign._id}).toArray()

points.forEach(point => {
const result = [ point._id, point.lon, point.lat ]
for(let i=0; i < nInspections; i++) {

for (let i= 0; i < nInspections; i++) {
var inspection = point.inspection[i]

if (point.userName[i]) {
result.push(point.userName[i].toLowerCase())
result.push(inspection.counter)

for(var j=0; j < inspection.form.length; j++) {
for(var j= 0; j < inspection.form.length; j++) {
var form = inspection.form[j]

for(var y=form.initialYear; y <= form.finalYear; y++) {
for(var y = form.initialYear; y <= form.finalYear; y++) {
result.push(form.landUse)
result.push(form.pixelBorder)
}
}
}

}

const consolidated = point.classConsolidated
const consolidated = point.classConsolidated;

if (consolidated) {
for(let i=0; i < consolidated.length; i++) {
result.push(consolidated[i])
}

result.push(point.pointEdited)
}

csvStream.write(result)
})

csvStream.end();

csvStream.pipe(response).on('end', () => response.end());
Expand Down
2 changes: 1 addition & 1 deletion src/server/middleware/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function(app) {

Cache.populateCache = function(requestPointCache, pointCacheCompĺete, finished) {

var periods = ['DRY','WET']
var periods = ['DRY', 'WET']

var getRequestTasks = function(point, campaign) {

Expand Down
1 change: 0 additions & 1 deletion src/server/routes/supervisor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = function (app) {

var points = app.controllers.supervisor;

app.get('/service/points/csv', points.csv);
Expand Down

0 comments on commit cb08f4f

Please sign in to comment.