TagSpaces is an offline, open source, document manager with tagging support
Perspective health is now working with the weight data
uggrock9f19ed2a8df3
diff --git a/data/ext/perspectiveHealth/extension.js b/data/ext/perspectiveHealth/extension.jsindex a3e95eabb..b568020b5 100644--- a/data/ext/perspectiveHealth/extension.js+++ b/data/ext/perspectiveHealth/extension.js@@ -44,7 +44,7 @@ define(function(require, exports, module) {switch (vizMode) {case "quantYours":require([- extensionDirectory+'/quantifiedSelfViz.js',+ extensionDirectory+'/myweight.js','css!'+extensionDirectory+'/styles.css',], function(viz) {d3.select("svg").remove();@@ -76,12 +76,32 @@ define(function(require, exports, module) {}var initUI = function() {++ viewToolbar.append($("<div >", {+ class: "btn-group",+ "data-toggle": "buttons-radio",+ })++ .append($("<button>", {+ class: "btn ",+ title: "Create new file",+ id: extensionID+"CreateFileButton",+ })+ .click(function() {+ TSCORE.showFileCreateDialog();+ })+ .append( "<i class='icon-plus'>" )+ )+ ); // end button group++viewToolbar.append($("<div >", {class: "btn-group","data-toggle": "buttons-radio",})+.append($("<button>", {class: "btn",title: "Show Quantified Yourself Graphic",@@ -95,8 +115,28 @@ define(function(require, exports, module) {TSCORE.IO.createDirectoryIndex(TSCORE.currentPath);}).prepend( "<i class='icon-tasks' />")- )- ) // end button group+ )+ ); // end button group++ viewToolbar.append($("<div >", {+ class: "btn-group",+ })+ .append($("<button>", {+ class: "btn",+ title: "Exports current table data as CSV",+ id: extensionID+"ExportButton",+ })+ .click(function() {+ var dialogContent = $('<textarea>', {+ style: "width: 500px; height: 350px;",+ text: TSCORE.exportFileListCSV(TSCORE.fileList)+ });+ TSCORE.showAlertDialog(dialogContent,"Export to CSV Dialog");+ })+ .append( $("<i>", { class: "icon-download-alt", }) )+ )++ ); // end toolbar}diff --git a/data/ext/perspectiveHealth/myweight.js b/data/ext/perspectiveHealth/myweight.jsindex 050c05501..4eada3c4d 100644--- a/data/ext/perspectiveHealth/myweight.js+++ b/data/ext/perspectiveHealth/myweight.js@@ -10,8 +10,50 @@ define(function(require, exports, module) {require("d3");+// /media/z/TagSpaces/sandbox/demo/Weight/[20120113 WEI89.6kg 30.2% 48.9% 36.0% BON2.0kg].tsd,,0,20120113,WEI89.6kg,DA30.2%,DB48.9%,DC36.0%,BON2.0kg++ function getData() {+ // Other posibility - d3.csv.parse(TSCORE.exportFileListCSV(TSCORE.fileList)); // requers unsafe-eval in the chrome manifest+ var rawData = TSCORE.exportFileListArray(TSCORE.fileList);+ var parsedData = [];+ rawData.forEach(function(d) {+ parsedData.push({+ "Date": d.tag0,+ "Weight in kg": +extractTagInfo(d.tag1).data,+ "Fat in %": +extractTagInfo(d.tag2).data,+ "Wather in %": +extractTagInfo(d.tag3).data,+ "Muscles in %": +extractTagInfo(d.tag4).data,+ "Bones in kg": +extractTagInfo(d.tag5).data,+ });+ })+ return parsedData;+ }++ // Input DA30.3kg+ function extractTagInfo(input) {+ // TODO regex not ready+ var tagSplit = /[0-9]+/g;+ var prefix = "";+ var postfix = "";++ var tagSplitArr = (""+input).match(tagSplit);+ if(tagSplitArr != null && tagSplitArr.length > 0) {+ prefix = tagSplitArr[0];+ postfix = tagSplitArr[tagSplitArr.length-1];+ }++ var dataRE = /[+-]?\d+\.\d+/g;+ var data = 0;+ var dataArr = (""+input).match(dataRE);+ if(dataArr != null && dataArr.length > 0) {+ data = parseFloat(dataArr[0]);+ }++ return { "prefix": prefix, "data": data, "postfix": postfix };+ }+function draw(svg) {- console.log("Drawing Quantified Self");+ console.log("Drawing My Weight");var margin = {top: 20, right: 20, bottom: 30, left: 40},width = svg.attr("width") - margin.left - margin.right,@@ -38,19 +80,21 @@ define(function(require, exports, module) {.orient("left").tickFormat(d3.format(".2s"));- // var data = d3.csv.parse(TSCORE.PerspectiveManager.csvExport());- var data = d3.csv.parse(tmpData);- color.domain(d3.keys(data[0]).filter(function(key) { return key !== "State"; }));++ var data = getData();++ color.domain(d3.keys(data[0]).filter(function(key) { return key !== "Date"; }));data.forEach(function(d) {var y0 = 0;d.ages = color.domain().map(function(name) { return {name: name, y0: y0, y1: y0 += +d[name]}; });d.total = d.ages[d.ages.length - 1].y1;});++ // Sorting by date+ data.sort(function(a, b) { return b.Date - a.Date; });- data.sort(function(a, b) { return b.total - a.total; });-- x.domain(data.map(function(d) { return d.State; }));+ x.domain(data.map(function(d) { return d.Date; }));y.domain([0, d3.max(data, function(d) { return d.total; })]);svg.append("g")@@ -66,13 +110,14 @@ define(function(require, exports, module) {.attr("y", 6).attr("dy", ".71em").style("text-anchor", "end")- .text("Population");+ .text("Health Data");var state = svg.selectAll(".state").data(data).enter().append("g").attr("class", "g")- .attr("transform", function(d) { return "translate(" + x(d.State) + ",0)"; });+ //.attr("transform", function(d) { return "translate(" + (d.x + d.dx / 2) + "," + (d.y + d.dy / 2) + ")rotate(90)"; })+ .attr("transform", function(d) { return "translate(" + x(d.Date) + ",0)"; });state.selectAll("rect").data(function(d) { return d.ages; })@@ -102,16 +147,6 @@ define(function(require, exports, module) {.text(function(d) { return d; });}-- var tmpData = "State,Under 5 Years,5 to 13 Years,14 to 17 Years,18 to 24 Years,25 to 44 Years,45 to 64 Years,65 Years and Over\n"+- "AL,310504,552339,259034,450818,1231572,1215966,641667\n"+- "AK,52083,85640,42153,74257,198724,183159,50277\n"+- "AZ,515910,828669,362642,601943,1804762,1523681,862573\n"+- "AR,202070,343207,157204,264160,754420,727124,407205\n"+- "CA,2704659,4499890,2159981,3853788,10604510,8819342,4114496\n"+- "CO,358280,587154,261701,466194,1464939,1290094,511094";--// Methodsexports.draw = draw;