@@ -5,6 +5,11 @@ var path = require('path');
55var glob = require ( "glob" ) ;
66var masterpw = "gulli" ;
77
8+ //Global counter variables
9+ var doneSimulations = 0 ;
10+ var openSimulations = 0 ;
11+
12+
813
914// Required modules for form handling
1015var express = require ( 'express' ) ,
@@ -19,17 +24,57 @@ var DEFAULT_MINIMUM_TIMEOUT = 500;//in sec
1924router . get ( '/' , function ( req , res ) {
2025 var db = req . db ;
2126 var activeclients = db . collection ( 'activeclients' ) ;
22- console . log ( "Delivering index-page." ) ;
23-
24- removeOldClientsFromList ( db , function ( error ) {
25- res . render ( 'index' , {
26- title : 'TimeNET distribution server' ,
27- clientcount : Math . round ( global . clientcount ) ,
28- clientsrunning : global . clientsrunning
29- } ) ;
30-
31- } ) ;
27+ var simlist = db . collection ( 'simlist' ) ;
28+
3229
30+ /*console.log("Delivering index-page.");*/
31+ simlist . find ( { simulated : false } , function ( err , result ) {
32+ if ( err ) {
33+ console . log ( "Error finding open simulations in db." ) ;
34+ } else {
35+ //console.log("Will try to count open simulations.");
36+ if ( result != null ) {
37+ result . count ( function ( err , count ) {
38+ if ( err ) {
39+ console . log ( "Error counting open simulations." ) ;
40+ } else {
41+ openSimulations = count ;
42+ //console.log("Number of open Simulations is:"+openSimulations);
43+
44+ simlist . find ( { simulated : true } , function ( err , result ) {
45+ if ( err ) {
46+ console . log ( "Error finding done simulations in db." ) ;
47+ } else {
48+ //console.log("Will try to count open simulations.");
49+ if ( result != null ) {
50+ result . count ( function ( err , count ) {
51+ if ( err ) {
52+ console . log ( "Error counting done simulations." ) ;
53+ } else {
54+ doneSimulations = count ;
55+ //console.log("Number of done Simulations is:"+doneSimulations);
56+
57+ removeOldClientsFromList ( db , function ( error ) {
58+ res . render ( 'index' , {
59+ title : 'TimeNET distribution server' ,
60+ clientcount : Math . round ( global . clientcount ) ,
61+ clientsrunning : global . clientsrunning ,
62+ opensimulations : openSimulations ,
63+ donesimulations : doneSimulations ,
64+ percentagedone : Math . round ( ( doneSimulations * 100 ) / ( doneSimulations + openSimulations ) ) || 0
65+ } ) ;
66+
67+ } ) ;
68+ }
69+ } ) ;
70+ } //End if
71+ } //End else
72+ } ) ;
73+ }
74+ } ) ;
75+ } //End if
76+ } //End else
77+ } ) ;
3378} ) ;
3479
3580
@@ -326,7 +371,8 @@ router.post('/rest/log/upload', function (req, res) {
326371
327372
328373 form . parse ( req , function ( err , fields , files ) {
329- var old_path = files . attachment . path ,
374+ try {
375+ var old_path = files . attachment . path ,
330376 file_size = files . attachment . size ,
331377 file_name = files . attachment . name ,
332378 simid = fields . simid ,
@@ -370,7 +416,11 @@ router.post('/rest/log/upload', function (req, res) {
370416 } ) ;
371417
372418 } ) ;
373- } ) ;
419+
420+ } catch ( e ) {
421+ console . log ( "Error while uploading logfile. " ) ;
422+ }
423+ } ) ;
374424
375425} ) ;
376426
@@ -679,6 +729,7 @@ function removeOldClientsFromList(db, cb) {
679729
680730 }
681731 }
732+ if ( global . clientsrunning == NaN ) global . clientsrunning = 0 ;
682733 } ) ;
683734
684735 //console.log("Simulating Clients:"+global.clientsrunning);
0 commit comments