Esempio n. 1
0
 .on("compare location timeline", function (eventId, locId, err, data) {
     if (eventId == reqId) {
         // if there is an error, send the error message to the web browser
         if (err) res.json({error: err});
         else {
             var storeFrontClients, name;
             // get the name of the location based on the locationID
             name = Location.getLocationName(req.session.locations, locId);
             data["times"].forEach(function (currentData){
                 // for each "time" entry, calculate the storefront conversion
                 if (currentData['uniqueClients'] == 0) storeFrontClients = 0;
                 else storeFrontClients = ((currentData['engagedClients'] / currentData['uniqueClients']) * 100).toFixed(0);
                 // add the storefront conversion the the entry
                 currentData['storefrontClients'] = parseInt(storeFrontClients);
             });
             // create an array with all the time values (used for the xAxis on the charts)
             if (timeserie.length == 0){
                 data['times'].forEach(function(entry){
                     timeserie.push(entry['time']);
                 })
             }
             //timeserie = data['times']["time"];
             // add the array of values from this location to the final array
             dataLocation.push({
                 name: name,
                 data: data['times']
             });
             locDone++;
         }
         // call the "compare location timeline finished" event
         eventEmitter.emit("compare location timeline finished", eventId);
     }
 })
Esempio n. 2
0
 function (err, data) {
     if (err) res.json({error: err});
     else {
         var storeFrontClients, name;
         // calculate the storefront conversion
         if (data['uniqueClients'] == 0) storeFrontClients = 0;
         else storeFrontClients = ((data['engagedClients']/data['uniqueClients'])*100).toFixed(0);
         // get the location name
         name = Location.getLocationName(req.session.locations, this.location);
         // add each locations to the "bestLocations" dictionary
         bestLocations[this.location] = {
             name: name,
             uniqueClients: data['uniqueClients'],
             engagedClients: data['engagedClients'],
             passersbyClients: data['passersbyClients'],
             associatedClients: data['associatedClients'],
             unassociatedClients: data['unassociatedClients'],
             storeFrontClients: storeFrontClients
         };
         locDone++;
         // if all the locations are done, will send the response back to the web browser
         if (locDone == buildings.length) {
             res.json({
                 error: null,
                 data: {
                     bestLocations: bestLocations
                 }
             })
         }
     }
 }.bind({location: location}));
Esempio n. 3
0
     .on("compare location polar location", function (eventId, locId, err, data) {
     // validate that this request is sent from this same function call
     if (eventId == reqId) {
         // if there is an error, send the error message to the web browser
         if (err) res.json({error: err});
         else {
             // get the name of the location based on the locationID
             var name = Location.getLocationName(req.session.locations, locId);
             var result = {
                 locationId: locId,
                 name: name,
                 uniqueClients: data['uniqueClients'],
                 engagedClients: data['engagedClients'],
                 passersbyClients: data['passersbyClients'],
                 associatedClients: data['associatedClients'],
                 unassociatedClients: data['unassociatedClients'],
                 newClients: data['newClients'],
                 returningClients: data['returningClients']
             };
             // store the result
             locResult.push(result);
             locDone++;
         }
         // got to the event "compare location polar finished"
         eventEmitter.emit("compare location polar finished", eventId);
     }
 })