Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thing dans co2 #209

Open
wants to merge 69 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
45e4347
Merge branch 'pixelhumain-master'
Danzal974 Mar 16, 2017
022d573
Merge branch 'pixelhumain-master'
Danzal974 Mar 17, 2017
ca58385
Merge branch 'pixelhumain-master'
Danzal974 Mar 17, 2017
5764fe5
Merge branch 'pixelhumain-master'
Danzal974 Mar 17, 2017
10eea6c
Merge branch 'pixelhumain-master'
Danzal974 Mar 17, 2017
7486fd3
Merge branch 'pixelhumain-master'
Danzal974 Mar 18, 2017
5f9b084
Merge branch 'pixelhumain-master'
Danzal974 Mar 20, 2017
010eaff
Merge branch 'pixelhumain-master'
Danzal974 Mar 21, 2017
400cd6d
Merge branch 'pixelhumain-master'
Danzal974 Mar 22, 2017
8847202
Merge branch 'pixelhumain-master'
Danzal974 Mar 22, 2017
0cda37e
Merge branch 'pixelhumain-master'
Danzal974 Mar 23, 2017
5a73600
Ajout de thing graph dans CO2
Danzal974 Mar 23, 2017
28452cd
modifié : docs/bugs.org
Danzal974 Mar 23, 2017
96337fe
Merge branch 'pixelhumain-master'
Danzal974 Mar 23, 2017
86ea1ea
modifié : views/thing/graph.php
Danzal974 Mar 24, 2017
2548cfb
modif thing/manage
Danzal974 Mar 27, 2017
92d7afb
Merge branch 'pixelhumain-master'
Danzal974 Mar 27, 2017
6e29d26
nouveau fichier : assets/js/thing/graph.js
Danzal974 Mar 28, 2017
4976eb0
Merge branch 'pixelhumain-master'
Danzal974 Mar 28, 2017
9f74e91
modifié : assets/js/sig/map_initializer.js
Danzal974 Mar 29, 2017
741811c
Merge branch 'pixelhumain-master'
Danzal974 Mar 29, 2017
9abdace
modifié : assets/js/thing/graph.js
Danzal974 Apr 3, 2017
8753c6b
Merge branch 'pixelhumain-master'
Danzal974 Apr 3, 2017
4881729
modifié : assets/js/thing/graph.js
Danzal974 Apr 7, 2017
f13294e
Merge branch 'pixelhumain-master'
Danzal974 Apr 7, 2017
6342d47
modifié : assets/js/thing/graph.js
Danzal974 Apr 15, 2017
003d722
Merge branch 'pixelhumain-master'
Danzal974 Apr 15, 2017
a170195
nouveau fichier : config/CO2/thing.json
Danzal974 Apr 19, 2017
5504814
Merge branch 'pixelhumain-master'
Danzal974 Apr 19, 2017
d18179d
modifié : assets/js/co.js
Danzal974 Apr 20, 2017
1b104a8
Merge branch 'pixelhumain-master'
Danzal974 Apr 20, 2017
f4bd20b
Merge branch 'master' of https://github.com/pixelhumain/co2 into pixe…
Danzal974 Apr 21, 2017
4258897
Merge branch 'pixelhumain-master'
Danzal974 Apr 21, 2017
a0d8839
modifié : assets/js/co.js
Danzal974 Apr 21, 2017
14bfd38
Merge branch 'master' of https://github.com/pixelhumain/co2 into pixe…
Danzal974 Apr 21, 2017
ab004f8
Merge branch 'pixelhumain-master'
Danzal974 Apr 21, 2017
262cb54
thing.manage 2 updates features done
Danzal974 Apr 25, 2017
6d5e95f
refactor thing metadata dans poi
Danzal974 Apr 28, 2017
da4424e
Merge branch 'master' of https://github.com/pixelhumain/co2 into pixe…
Danzal974 Apr 28, 2017
2cea822
Merge branch 'master' of https://github.com/pixelhumain/co2 into pixe…
Danzal974 Apr 28, 2017
a5b49db
Merge branch 'pixelhumain-master'
Danzal974 Apr 28, 2017
b6edc85
modifié : views/thing/manage.php
Danzal974 May 3, 2017
378d152
Merge branch 'master' of https://github.com/pixelhumain/co2 into pixe…
Danzal974 May 3, 2017
1119bc5
Merge branch 'pixelhumain-master'
Danzal974 May 3, 2017
0cf4e85
modifié : views/thing/scklastestreadings.php
Danzal974 May 6, 2017
74c9b47
modifié : views/thing/graph.php
Danzal974 May 9, 2017
f048fe5
Merge branch 'master' of https://github.com/pixelhumain/co2 into pixe…
Danzal974 May 9, 2017
8244438
Merge branch 'pixelhumain-master'
Danzal974 May 9, 2017
e913d59
modifié : config/CO2/thing.json
Danzal974 May 12, 2017
43f2d4f
Merge branch 'master' of https://github.com/pixelhumain/co2 into pixe…
Danzal974 May 12, 2017
b37bf26
Merge branch 'pixelhumain-master'
Danzal974 May 12, 2017
fc30c8e
modifié : assets/js/thing/graph.js ;
Danzal974 May 24, 2017
503f5a9
Merge branch 'master' of https://github.com/pixelhumain/co2 into pixe…
Danzal974 May 24, 2017
2c27da6
Merge branch 'pixelhumain-master'
Danzal974 May 24, 2017
cb26fd4
modifié : assets/js/thing/graph.js
Danzal974 May 26, 2017
ee4b41f
Merge branch 'master' of https://github.com/pixelhumain/co2 into pixe…
Danzal974 May 26, 2017
8713eab
Merge branch 'pixelhumain-master'
Danzal974 May 26, 2017
cc307fd
Refrator (en cours) de graphe pour corriger le probleme des axis.
Danzal974 May 28, 2017
7d9af8e
Merge branch 'master' of https://github.com/pixelhumain/co2 into pixe…
Danzal974 May 28, 2017
6c72105
Merge branch 'pixelhumain-master'
Danzal974 May 28, 2017
2ea9e51
modifié : assets/js/thing/graph.js
Danzal974 Jun 1, 2017
8cb0175
Merge branch 'master' of https://github.com/pixelhumain/co2 into pixe…
Danzal974 Jun 1, 2017
7eb5c0a
Merge branch 'pixelhumain-master'
Danzal974 Jun 1, 2017
1920b6a
modifié : assets/js/thing/graph.js
Danzal974 Jun 1, 2017
99ce7ef
modifié : docs/specs/Thing.md
Danzal974 Jun 15, 2017
bfd46dd
Merge branch 'master' of https://github.com/pixelhumain/co2 into pixe…
Danzal974 Jun 15, 2017
044fd1f
Merge branch 'pixelhumain-master'
Danzal974 Jun 15, 2017
e3d7f53
Merge branch 'master' of https://github.com/pixelhumain/co2 into pixe…
Danzal974 Jun 24, 2017
25c8397
Merge branch 'pixelhumain-master'
Danzal974 Jun 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions assets/js/co.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,14 @@ var urlCtrl = {
"#define." : {title:'TAG MAP ', icon : 'map-marker', action:function( hash ){ showDefinition("explain"+hash.split('.')[1]) } },
"#data.index" : {title:'OPEN DATA FOR ALL', icon : 'fa-folder-open-o'},
"#opendata" : {"alias":"#data.index"},
"#thing.graph" : {title:'GRAPH IOT', icon : 'fa-line-chart'},
"#thing.manage" : {title:'MANAGE IOT', icon : 'fa-database'},
"#thing.updatesckdevices" : {title:'UPDATE SCK', icon : 'fa-database'},
"#thing.scklastestreadings" : {title:'LASTEST READING SCK', icon : 'fa-database'},
"#thing.getsckdataincodb" : {title:'DATA RECORD SCK', icon : 'fa-database'},
"#thing.synthetizesckdata" : {title:'SYNTHETIZE RECORD SCK', icon : 'fa-database'},
"#search" : { "title":'SEARCH AND FIND', "icon" : 'map-search', "hash" : "#default.directory", "preaction":function( hash ){ return searchByHash(hash);} },

},
shortVal : ["p","poi","s","o","e","pr","c","cl"/* "s","v","a", "r",*/],
shortKey : [ "citoyens","poi" ,"siteurl","organizations","events","projects" ,"cities" ,"classified"/*"entry","vote" ,"action" ,"rooms" */],
Expand Down
1 change: 1 addition & 0 deletions assets/js/sig/map_initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
"poi.openScene" : "poi-marker-default",
"poi.stand" : "poi-marker-default",
"poi.parking" : "poi-marker-default",
"poi.smartCitizen" : "poi-marker-default",

"entry" : "entry-marker-default",
"action" : "action-marker-default",
Expand Down
313 changes: 313 additions & 0 deletions assets/js/thing/graph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,313 @@
/**
*@author: Danzal
*
*/
function showAllGraph(){ $(".graphs").show(); }
function showGraph(figGraph){ $("#"+figGraph).show(); }
function hideAllGraph(){ $(".graphs").hide(); }
function hideGraph(figGraph){ $("#"+figGraph).hide(); }

function hideAllChart(sourcedb){ $(".chart_"+sourcedb).hide(); }
function showAllChart(sourcedb){ $(".chart_"+sourcedb).show(); }

function showHideChart(valuebtn){
//var sourcedb = $(this).data("sourcedb") ; // amélioration pour un eselection direct
var sourceText="";
var toShow="";
switch (valuebtn) {
case 0 :
if(!graphReady.dCOdb){
sourceText="la base de données de Communecter";
setGraphFromCoDB();
}
hideAllChart("dAPIsc");
toShow="dCOdb";
break;
case 1:
if(!graphReady.dAPIsc){
sourceText="l'API de smartcitizen";
setGraphFromAPIsmartcitizen();
}
hideAllChart("dCOdb");
toShow="dAPIsc";
break;
/*case 2:
//TODO : redrawBothChartGraph();
showAllChart("dCOdb");
showAllChart("dAPIsc");
break;*/
}
if((!graphReady.dCOdb && valuebtn==0) || ( !graphReady.dAPIsc && valuebtn==1) ){
$.blockUI({ message : '<span class="homestead"><i class="fa fa-spinner fa-circle-o-noch"></i> Chargement des données depuis '+sourceText+' en cours ... </span>' });
}else{
graphesRedraw(toShow);
}
showAllChart(toShow);
$("#btnTempAndHum").click();
$("#legend-graph").removeClass("hidden");

}

function setSVGForSensor(sensor,sensorKey) {

var svgId = "sensor"+sensor;
var figGraph = "graphe_"+sensor;
var gId = svgId+"_g";

var svgObj = d3.select("#"+figGraph)
.append("svg").attr("width",svgwidth).attr("height",svgheight)
.attr("viewBox","0 0 "+svgwidth+" "+svgheight)
.attr("preserveAspectRatio","xMidYMid meet")
.attr("class","col-sm-12 svggraph")
.attr("id", svgId);

var g = svgObj
.append("g")
.attr("transform", "translate(" + gmargin.left + "," + gmargin.top + ")")
.attr("id", gId);

var captionSensor = d3.select("#"+figGraph)
.append("figcaption")
.text("Graph of sensor "+infoSensors[svgId].name+" ("+infoSensors[svgId].description+")");

multiGraphe[sensorKey] = {svgid : svgId,
svg : svgObj,
mesure : {description : "", unit : "" },
dimension : { width : +gwidth,
height : +gheight,
margin : gmargin },
gid : gId ,
domain : {Yn : null, Ym : null, Xn : vXn, Xm : vXm , xDomainInitialized : false},
data : {},
divgraphid : figGraph,
urlReqApi : ""
};

mylog.log('multiGraphe['+sensorKey+'] : ');
mylog.log(multiGraphe[sensorKey]);
}

function setLegend(deviceId,strkCol){

var idIM = 'icnmin_'+deviceId;
var idTL = 'textdevice_'+deviceId;

var legendILSC="<a href='https://smartcitizen.me/kits/"+deviceId+"' target='_blank'><i class='fa fa-minus' id='"+idIM+"' style='color:"+strkCol+";'></i> SCK device "+deviceId+"</a>";
// var iconMinus = "<i class='fa fa-minus' id='"+idIM+"' style='color:"+strkCol+";'></i>";
var dLegend = d3.select("#legend").append("div").attr("id","legend_"+deviceId).attr("class","col-sm-12 col-xs-12");
dLegend.append("span").html(legendILSC);
}

function setStrokeColorAndLegendForDevice(device) {
//var stId = "sCol_"+device;
if(strockeColorArray[device] == null ){
var strockeColor = "rgb("+Math.floor((Math.random()*220)+1)+","+Math.floor((Math.random()*220)+1)+","+Math.floor((Math.random()*220)+1)+")";
strockeColorArray[device]=strockeColor;
setLegend(device,strockeColor);
}
//return strockeColor;
}

function setGraphDomain(data, sensorkey,redraw){
mylog.log("setGraphDomain");
if(redraw==true){
multiGraphe[sensorkey].domain.Yn == null;
multiGraphe[sensorkey].domain.Ym == null;
min[sensorkey]=null;
max[sensorkey]=null;
}

for(id in data){
var dDS = data[id][sensorkey];
//mylog.log("dDS : " );
//mylog.log(dDS);
if(dDS.length>=1){
min[sensorkey]=d3.min( dDS, function(d){ return d.values;});
max[sensorkey]=d3.max( dDS, function(d){ return d.values;});
//mylog.log("- sensorkey :"+ sensorkey+ ": min : "+ min +" -- max: "+max);
if (multiGraphe[sensorkey].domain.Yn == null || multiGraphe[sensorkey].domain.Yn > min[sensorkey]) {
multiGraphe[sensorkey].domain.Yn = min[sensorkey];
//mylog.log("multiGraphe["+sensorkey+"].domain.Yn : " + multiGraphe[sensorkey].domain.Yn);
}
if (multiGraphe[sensorkey].domain.Ym == null || multiGraphe[sensorkey].domain.Ym < max[sensorkey]) {
multiGraphe[sensorkey].domain.Ym = max[sensorkey];
//mylog.log("multiGraphe["+sensorkey+"].domain.Ym : "+multiGraphe[sensorkey].domain.Ym);
}
}
}
}


function setAxisXY(sensorKey){
setAxisX(sensorKey);
setAxisY(sensorKey);
}


function setAxisX(sensorKey){
mylog.log(" --- setAxisX --- ");
var gId = multiGraphe[sensorKey].gid;
var g = d3.select("#"+gId);
var xAxisId="xAxis"+multiGraphe[sensorKey].svgid;
//var height = multiGraphe[sensorKey].dimension.height;

d3.select("#"+xAxisId).remove(); // TODO refaire la selection sur le graphe sensor

g.append("g")
.attr("id", xAxisId)
.attr("class", "theAxis")
.attr("transform", "translate(0," + gheight + ")")
.call(d3.axisBottom(x))
/// *
//.append("text")
//.attr("fill","#000")
//.attr("x", gwidth)
//.attr("text-anchor","end")
//.text("time")
;
}

function setAxisY(sensorKey){
mylog.log(" --- setAxisY --- ");

var gId = multiGraphe[sensorKey].gid;
var g = d3.select("#"+gId);
var yAxisId="yAxis"+ multiGraphe[sensorKey].svgid;

d3.select("#"+yAxisId).remove(); // TODO refaire la selection sur le graphe sensor

var sensorkunit = sensorKey+" "+infoSensors[multiGraphe[sensorKey].svgid].unit ; // mettre dans le text

g.append("g")
.attr("id", yAxisId)
.attr("class", "theAxis")
.call(d3.axisLeft(y))
.append("text")
.attr("fill","#000")
.attr("transform", "rotate(-90)")
.attr("y", 8)
.attr("dy", "0.71em")
.attr("text-anchor","end")
.text(sensorkunit)
;

}

function tracer(da,device,sensorKey,strokeColor="blue",source, strokeWidth=1.5){
mylog.log("da in tracer");
mylog.log(da);
if (da.length>0){
mylog.log("----------- da.length > 0 : tracer ! -------- ");
mylog.log("-- tracer - device : "+device+" sensor "+sensorKey);
var g = d3.select("#"+multiGraphe[sensorKey].gid);

var gpathId = source+"_gpId_"+device+multiGraphe[sensorKey].svgid; //ex : [source]_gpId_4162sensor17
var graphClassSensor = "gcs_"+dataSensors[sensorKey].id+" "+source+" chart_"+source+" "+device +" chart_graph" ;
g.append("path")
.datum(da)
.attr("fill", "none")
.attr("class", graphClassSensor)
.attr("id", gpathId)
.attr("stroke", strokeColor)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("stroke-width", strokeWidth)
.attr("d", line);
/* TODO afficher text du device lors d'un survol avec la souris
g.append("text")
.datum(function(d){ return {value: d.values[d.values.length - 1]}; })
.attr("transform", function(d) { return "translate(" + x(d.values) + "," + y(d.timestamps) + ")"; })
.attr("x", 3)
.attr("dy", "0.35em")
.style("font", "10px sans-serif")
.text(function(d) { return d.values; });*/
}
$.unblockUI();

}

function graphesRedraw(source){
for(keySens in multiGraphe){
grapheOneSensor(keySens,source, true);
}
}

function grapheOneSensor(keySens,source, redraw) {
$.unblockUI();
var data = (source=="dCOdb")? dCOdb : dAPIsc;

setGraphDomain(data, keySens, redraw);
//TODO Prendre un domaine 10% plus grand que les data en Y 5%top et 5 bottom
y.domain([(multiGraphe[keySens].domain.Yn-1), (multiGraphe[keySens].domain.Ym+1)]);
setAxisY(keySens);

if(multiGraphe[keySens].domain.xDomainInitialized==false || redraw==true){
x.domain([multiGraphe[keySens].domain.Xn, multiGraphe[keySens].domain.Xm]);
setAxisX(keySens);
multiGraphe[keySens].domain.xDomainInitialized=true;
}

if(redraw==false){
for (dId in data){
tracer(data[dId][keySens], dId, keySens, strockeColorArray[dId],source);
}
}
if(graphReady[source]==false){
$(".svggraph").show();
$("#legend-graph").show();
graphReady[source]=true;
}
}

function fillArrayWithObjectTimestampsAndValues(readings, deviceid, sensorkey){
mylog.log("- fillArrayWithObjectTimestampsAndValues - ");

dAPIsc[deviceid][sensorkey] = readings.map(
function(item){
var ts = new Date();
ts.setTime(Date.parse(item[0]));
ts.setSeconds(0);
item[1] = +item[1];
return {timestamps : ts, values : item[1]};
}
);
//multiGraphe[sensorkey].data[deviceid] = dAPIsc[deviceid][sensorkey];
}

function dataSensorAdaptorTimestampsAndValues(convertedDataRecord,device){
mylog.log("--dataSensorAdaptorTimestampsAndValues--");
var dataCOdb={temp : [], hum : [], bat: [], panel : [], no2 : [], panel : [], co : [], noise : [], nets : [], light : []};
convertedDataRecord.forEach( function(item){
var ts = new Date();
ts.setTime(Date.parse(item.timestamp));
ts.setSeconds(0);

item.temp =+item.temp;
item.hum =+item.hum;
item.bat =+item.bat;
item.panel=+item.panel;
item.co =+item.co;
item.no2 =+item.no2;
item.light=+item.light;
item.nets =+item.nets;
item.noise=+item.noise;

dataCOdb.temp.push({timestamps : ts, values : item.temp});
dataCOdb.hum.push({timestamps : ts, values : item.hum});
dataCOdb.bat.push({timestamps : ts, values : item.bat});
dataCOdb.panel.push({timestamps : ts, values : item.panel});
dataCOdb.no2.push({timestamps : ts, values : item.no2});
dataCOdb.co.push({timestamps : ts, values : item.co});
dataCOdb.noise.push({timestamps : ts, values : item.noise});
dataCOdb.nets.push({timestamps : ts, values : item.nets});
dataCOdb.light.push({timestamps : ts, values : item.light});

}
);
dCOdb[device]=dataCOdb;

for (ks in multiGraphe){
multiGraphe[ks].data[device]=dataCOdb[ks];
}
//return dataCOdb;
}
10 changes: 10 additions & 0 deletions components/CommunecterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,20 @@ class CommunecterController extends Controller
"checkurlexists" => array('href' => "/ph/communecter/app/checkurlexists", "public" => true),
"rooms" => array('href' => "/ph/communecter/app/rooms", "public" => true),
"survey" => array('href' => "/ph/communecter/app/survey", "public" => true),
"thing" => array('href' => "/ph/communecter/app/thing", "public" => true),
),
"siteurl" => array(
"incnbclick" => array('href' => "ph/communecter/siteurl/incnbclick")
),
"thing" => array(
//"index" => array('href' => "/ph/communecter/thing/index", "public" => true ),
"graph" => array('href' => "/ph/communecter/thing/graph", "public" => true ),
"scklastestreadings" => array('href' => "/ph/communecter/thing/scklastestreadings", "public" => true ),
"updatesckdevices" => array('href' => "/ph/communecter/thing/updatesckdevices", "public" => true ),
"manage" => array('href' => "/ph/communecter/thing/manage","public"=>true),
"getsckdataincodb" => array('href' => "/ph/communecter/thing/getsckdataincodb","public"=>true),
"synthetizesckdata" => array('href' => "/ph/communecter/thing/synthetizesckdata","public"=>true),
),
);

function initPage(){
Expand Down
14 changes: 13 additions & 1 deletion config/CO2/params.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,19 @@
"icon" : "university",
"mainTitle" : "Partie Admin Public",
"placeholderMainSearch" : "Admin Public ..."
}
},

"#thing": {
"inMenu" : true,
"useHeader" : false,
"open" : true,
"subdomain" : "thing",
"subdomainName" : "Objets communectés",
"hash" : "#app.thing",
"icon" : "database",
"mainTitle" : "Les objets communectés",
"placeholderMainSearch" : "Les objets communectés ..."
}

}

Expand Down
Loading