From 0d1788396b1de29e8c6a49aac0ba24ad2bf2a6e9 Mon Sep 17 00:00:00 2001 From: dpaun Date: Wed, 21 Mar 2018 14:07:21 +0100 Subject: [PATCH] SWIK-1958 added accordion and thumbnail for predicion job --- .../analytics/addPerformancePredictionJob.js | 7 +- .../UserPerformancePredictionItem.js | 89 +++++++++++++------ .../UserPerformancePredictions.js | 46 ++++++++-- services/analytics.js | 49 +++++++--- stores/UserPerformancePredictionsStore.js | 2 +- 5 files changed, 146 insertions(+), 47 deletions(-) diff --git a/actions/analytics/addPerformancePredictionJob.js b/actions/analytics/addPerformancePredictionJob.js index ee264a06b..2855281d1 100644 --- a/actions/analytics/addPerformancePredictionJob.js +++ b/actions/analytics/addPerformancePredictionJob.js @@ -3,13 +3,14 @@ import serviceUnavailable from '../error/serviceUnavailable'; export default function addPerformancePredictionJob(context, payload, done) { log.info(context, payload); - context.service.create('analytics.prediction', payload, {timeout: 20 * 1000}, (err, res) => { + context.dispatch('ADD_PERFORMANCE_PREDICTION_SUCCESS', payload); + + context.service.create('analytics.prediction', payload, {timeout: 60 * 1000}, {timeout: 600 * 1000}, (err, res) => { if (err) { log.error(context, {filepath: __filename}); context.executeAction(serviceUnavailable, payload, done); - context.dispatch('ADD_PERFORMANCE_PREDICTION_FAILED'); } else { - context.dispatch('ADD_PERFORMANCE_PREDICTION_SUCCESS', res); + context.dispatch('LOAD_USER_PERFORMANCE_PREDICTIONS_SUCCESS', res);//list of all prediction jobs received } done(); }); diff --git a/components/User/UserProfile/UserAnalytics/UserPerformancePredictionItem.js b/components/User/UserProfile/UserAnalytics/UserPerformancePredictionItem.js index 4e60c85eb..e31fec787 100644 --- a/components/User/UserProfile/UserAnalytics/UserPerformancePredictionItem.js +++ b/components/User/UserProfile/UserAnalytics/UserPerformancePredictionItem.js @@ -1,6 +1,9 @@ import React from 'react'; import {List, Icon, Button} from 'semantic-ui-react'; +import { NavLink } from 'fluxible-router'; import {formatDate} from '../../../Deck/ActivityFeedPanel/util/ActivityFeedUtil'; +import { Microservices } from '../../../../configs/microservices'; +import Thumbnail from '../../../common/Thumbnail'; class UserpPerformancePredictionItem extends React.Component { @@ -8,52 +11,84 @@ class UserpPerformancePredictionItem extends React.Component { const prediction = this.props.prediction; const resultIcons = (!prediction.result) ? '' : (prediction.result < 50) ? ( -
+
) : (prediction.result < 80) ? ( -
+
) : ( -
- +
+
); - return ( - - + let thumbnailURL = `${Microservices.file.uri}/thumbnail/slide/`; + if (prediction.deckFirstSlide) { + thumbnailURL += prediction.deckFirstSlide; + if (prediction.deckTheme) { + thumbnailURL += '/' + prediction.deckTheme; + } + } else { + thumbnailURL = ''; + } - -
-
+ let duration = ''; + let msPerMinute = 60 * 1000; + let elapsed = new Date(prediction.finished).getTime() - new Date(prediction.started).getTime(); + if (elapsed < msPerMinute) { + duration = Math.round(elapsed/1000) + ' seconds'; + } else{ + duration = Math.round(elapsed/msPerMinute) + ' minutes'; + } + return ( +
+
+ +
+
-
-

{prediction.title}

-
-
- {(prediction.finished) ? 'Executed ' : 'Started '} - {formatDate(prediction.started)} -
-
- {(prediction.result) ? 'Predicted result: ' + prediction.result : ''} - {resultIcons} -
-
- {(prediction.accuracy) ? 'Accuracy: ' + Math.round(prediction.accuracy * 100) / 100 : ''} -
+
+ {prediction.title} +
+
+ {(prediction.finished) ? 'Executed ' : 'Started '} + {formatDate(prediction.started)} +
+
+ {(prediction.result) ? 'Predicted result: ' + Math.round(prediction.result * 100) / 100 : ''}
+
+ {resultIcons} +
+
+
+
+
+
+
+ {(prediction.deckId) ? 'Deck id: ' + prediction.deckId : ''} + + + +
+
+ {(prediction.started) ? 'Started: ' + prediction.started : ''} +
+
+ {(prediction.finished) ? 'Duration: ' + duration : ''}
- - - +
+
+
); } } diff --git a/components/User/UserProfile/UserAnalytics/UserPerformancePredictions.js b/components/User/UserProfile/UserAnalytics/UserPerformancePredictions.js index 77d8be131..a9e9a422e 100644 --- a/components/User/UserProfile/UserAnalytics/UserPerformancePredictions.js +++ b/components/User/UserProfile/UserAnalytics/UserPerformancePredictions.js @@ -11,16 +11,50 @@ class UserPerformancePredictions extends React.Component { e.preventDefault(); + + + //IMPLEMENT DECK SELECTION let deckId = 2000; + let deckTitle = 'testTitle'; + let deckFirstSlide = '14176-2' + let deckTheme = 'default'; - let uid = this.props.UserProfileStore.userid; - this.context.executeAction(addPerformancePredictionJob, {uid: uid, deckId: deckId}); + let userId = this.props.UserProfileStore.userid; + let started = new Date(); + let prediction = { + userId: userId, + deckId: deckId, + title: deckTitle, + started: started, + deckTheme: deckTheme, + deckFirstSlide: deckFirstSlide + } + this.context.executeAction(addPerformancePredictionJob, {prediction: prediction}); } + componentDidMount() { + this.enableAccordion(); + } + + componentDidUpdate() { + this.refreshAccordion(); + } + + enableAccordion(status) { + let accordionDIV = this.refs.predictionsList; + $(accordionDIV).find('.ui.accordion').accordion({ + exclusive: false + }); + } + + refreshAccordion(status) { + let accordionDIV = this.refs.predictionsList; + $(accordionDIV).find('.ui.accordion').accordion('refresh'); + } render() { const items = this.props.UserPerformancePredictionsStore.predictions ? ((this.props.UserPerformancePredictionsStore.predictions.length > 0) ? this.props.UserPerformancePredictionsStore.predictions.map((prediction, index) => { @@ -35,14 +69,16 @@ class UserPerformancePredictions extends React.Component {

Performance predictions

{loading} -
- {items} +
+
+ {items} +
); diff --git a/services/analytics.js b/services/analytics.js index 8d8adbc4f..4dffc781c 100644 --- a/services/analytics.js +++ b/services/analytics.js @@ -59,6 +59,8 @@ export default { // get the active revision of the deck let activeRevision = deck.revisions[deck.revisions.length-1]; predictions[i].title = activeRevision.title; + predictions[i].deckFirstSlide = activeRevision.firstSlide; + predictions[i].deckTheme = activeRevision.theme; } callback(null, {predictions: predictions}); @@ -78,33 +80,58 @@ export default { req.reqId = req.reqId ? req.reqId : -1; log.info({Id: req.reqId, Service: __filename.split('/').pop(), Resource: resource, Operation: 'create', Method: req.method}); let args = params.params? params.params : params; - let deckId = args.deckId; - let uid = args.uid; + let deckId = args.prediction.deckId; + let uid = args.prediction.userId; if (uid === undefined) { uid = 0; } - if(resource === 'analytics.prediction'){ + if(resource === 'analytics.prediction'){ rp.post({ uri: analyticsServiceUri + '/analytics/webresources/predictionjob/', proxy: '', body:JSON.stringify({ user_id: uid, deck_id: deckId - }) + }), + timeout: body.timeout }).then((res) => { + //LIST OF ALL PREDICTION JOBS RECEIVED + let predictions = JSON.parse(res); + //GET DATA FOR DECKS FROM DECK SERVICE + let deckPromises = []; - console.log(res); + // get details for the decks in the collection + for(let prediction of predictions){ + let deckId = prediction.deckId; + deckPromises.push( + rp.get({ + uri: `${Microservices.deck.uri}/deck/${deckId}`, + json: true, + timeout: body.timeout + }) + ); + } - callback(null, {prediction: JSON.parse(res)}); + Promise.all(deckPromises).then( (data) => { + let decks = data; + for (let i = 0; i < decks.length; i++) { + let deck = decks[i]; + // get the active revision of the deck + let activeRevision = deck.revisions[deck.revisions.length-1]; + predictions[i].title = activeRevision.title; + predictions[i].deckFirstSlide = activeRevision.firstSlide; + predictions[i].deckTheme = activeRevision.theme; + } + callback(null, {predictions: predictions}); + }).catch( (err) => { + console.log(err); + callback(null, {predictions: []}); + }); }).catch((err) => { console.log(err); - callback(err, {prediction: {}}); + callback(err, {predictions: []}); }); } } - - // other methods - // create: (req, resource, params, body, config, callback) => {}, - }; diff --git a/stores/UserPerformancePredictionsStore.js b/stores/UserPerformancePredictionsStore.js index 98a0fd45c..7176e992a 100644 --- a/stores/UserPerformancePredictionsStore.js +++ b/stores/UserPerformancePredictionsStore.js @@ -17,7 +17,7 @@ class UserPerformancePredictionsStore extends BaseStore { this.emitChange(); } addPredictionJob(payload) { - this.predictions.push(payload.prediction); + this.predictions.unshift(payload.prediction);//add to the beginning // this.showAddBox = false; this.emitChange(); }