2013-09-28

Get Smart

Call me envious, but my SSD just broke abruptly.
Dead.
Not even recognized by BIOS.
I had S.M.A.R.T. Monitoring enabled, but I had no signs of the impending doom.
At least mechanical disk usually begin to rattle a little before dying.

2013-09-22

Multiple Vertical Axes in Google Spreadsheet Charts in Javascript

This was tricky.
Chart options are documented in a wide galaxy of different documents, and none of them seems to explain multiple axes charts:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(GlideChartName);
var chart = sheet.newChart()
  .setChartType(Charts.ChartType.AREA)
  .addRange(sheet.getRange("A:A"))
  .addRange(sheet.getRange("B:B"))
  .setOption("title", "Chart Name")
  .setOption("width", 800)
  .setOption("height", 600)
  .setOption("hAxis.title", "X")
  .setOption("series", { 0: { targetAxisIndex: 0 }, 1: { targetAxisIndex: 1 } })
  .setOption("vAxes", { 0: { title: "Y1" }, 1: { title: "Y2" } })
  .setPosition(1, 1, 0, 0)
  .build();

sheet.insertChart(chart);

2013-09-21

TrickedIn?

What's going on with LinkedIn?
Some weeks ago the list of people I may know began containing a person I really know, but he's completely outside of my working circle.
We don't have any common contacts, he's even living in another country.
I only contacted him last year using the email address I used to register myself on LinkedIn, a yahoo address.
I used yahoo to contact him on gmail, I didn't send any email through LinkedIn nor did him.
Actually I can't think any other mean of relating the two of us other than looking at the history of our mailboxes.
And now this:
http://www.businessweek.com/news/2013-09-20/linkedin-customers-say-company-hacked-their-e-mail-address-books
Maybe 2 clues don't build an evidence, but they leave a doubt.

2013-09-15

Torque Log Analyzer Tool for Google Drive

NOTE: this post refers to an older version of Torque Log Analyzer.
The new version is here: http://torqueloganalyzer.blogspot.it/
Follow this link.




I leave the older version here for reference.




NOTE: this post has been updated: there is new code attached.

Following up my previous rants on driving gamification, I've made a prototype of a Log Analyzer for Torque, that computes some driving parameters.
It's particularly aimed for Toyota HSD hybrid cars.
It's written in Google Script for Google Drive, so it can be used on as many platforms as possible.

First, you need some logs from Torque: here is a tutorial on that.
The PIDs you need to log are:
"Speed (OBD)(km/h)"
"Engine RPM(rpm)"
"Batt Pack Current Val(Amperes)"
"State of Charge(%)"
These PIDs are contained in a HSD specific file you can find here.

Once you've logged your data with Torque, you should end up with a zip file.


you'll find the actual data inside a CSV file.


extract it.


drag it into google drive, selecting "Convert document"




google drive will convert it to a spreadsheet document.
warning: columns order and name may vary according to your PID logging configuration.


Open the newly created spreadsheet document.


Select "Tool/Script editor..."

Close the wizard window.


Delete any existing code.
Copy and paste the following code:

=== CUT HERE ===

// Torque Log Analyzer for Google Drive
//
// Alessandro Iacopetti, http://pleasedonttouchthescreen.blogspot.it/2013/09/torque-log-analyzer-tool-for-google.html
// free use for non-commercial purposes.
//
// usage:
// load your csv formatted torque log in an empty spreadsheet and then run this script against it
//
// 2013/09/15 - first release
// 2013/09/20 - added some sanity checks, speed variation index, ignitions count


// name of the columns we use
var OBDSpeedName = "Speed (OBD)(km/h)";
var RPMName = "Engine RPM(rpm)";
var BattPackCurrentName = "Batt Pack Current Val(Amperes)";
var SOCName = "State of Charge(%)";

// parameters
var SOCBestValue = 60;      // HSD system always tries to maintain this level
var IgnitionMinTime = 5;    // seconds under which ICE ignition is considered inefficient


// no user customization under this line

// support columns to be added
var GlideName = "Glide";
var SpeedVarName = "Speed Variation";

// position of columns used in calculation
var OBDSpeed = -1;
var RPM = -1;
var BattPackCurrent = -1;
var SOC = -1;
var Glide = -1;
var SpeedVar = -1;

var NumShortIgnitions = 0;
var NumIgnitions = 0;

function AnalyzeTorqueLogs() {
  
  // logging helpers
  
  function addLogSheet() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var activesheet = SpreadsheetApp.getActiveSheet();
    var sheet = ss.getSheetByName("Log");
    if (sheet == null) {
      sheet = ss.insertSheet("Log", 1);
    }
    sheet.setColumnWidth(1, 500);
    ss.setActiveSheet(activesheet);
  }
  
  function printLog(log) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var activesheet = SpreadsheetApp.getActiveSheet();
    var sheet = ss.getSheetByName("Log");
    sheet.appendRow([ log ])
    ss.setActiveSheet(activesheet);
  }
  
  
  // data processing
  
  function setDataName() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheets()[0];
    sheet.setName("Data");
  }
  
  // count RPM sequences != 0 less then minimum time
  function countShortIgnitions() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheets()[0];
    var range = sheet.getRange(RPM + "2:" + RPM);
    var height = range.getHeight();
    var values = range.getValues();

    sequencelength = 0;
    lastrpm = 0;
    for (var i = 0; i < height; ++i) {
      if (values[i] != 0) {
        sequencelength++;
        if (lastrpm == 0)
          NumIgnitions++;
      }
      if (values[i] == 0) {
        if (lastrpm != 0) {
          if (sequencelength < IgnitionMinTime)
            NumShortIgnitions++;
          sequencelength = 0;
        }
      }
      lastrpm = values[i];
    }
  }
    
  function addAnalysisSheet() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName("Analysis");
    if (sheet == null) {
      sheet = ss.insertSheet("Analysis", 1);
    }
    
    // SOC
    var values = [
      [ "Start SOC %" ],
      [ "End SOC %" ],
      [ "SOC Gain %" ],
      [ "Average SOC %" ],
      [ "Difference from best %" ],
      [ "Standard Deviation" ],
    ];
    var range = sheet.getRange(1, 1, 6, 1);
    range.setValues(values);
      
    var values = [
      [ "=Data!" + SOC + "2" ],
      [ "=INDEX(Data!" + SOC + ":" + SOC + "; COUNT(Data!" + SOC + ":" + SOC + "))" ],
      [ "=B2-B1" ],
      [ "=AVERAGE(Data!" + SOC + ":" + SOC + ")" ],
      [ "=B4-" + SOCBestValue ],
      [ "=STDEVP(Data!" + SOC + ":" + SOC + ")" ],
    ];
    var range = sheet.getRange(1, 2, 6, 1);
    range.setFormulas(values);
    range.setNumberFormat("0.00");
    
    printLog("SOC Analysis added");
    
    // Hybrid
    var values = [
      [ "ICE off %", "", "Percentage of trip time where the engine was off" ],
      [ "Ignitions", "", "Times ICE was turned on" ],
      [ "Inefficient Ignitions", "", "Times ICE was turned on for less than " + IgnitionMinTime + " seconds" ],
      [ "Glide %", "", "Percentage of driving time where the car was gliding" ],
      [ "Longest Glide sequence", "", "Longest glide, in seconds" ],
      [ "Battery Stress", "", "Quadratic average of battery current flow" ],
    ];
    var range = sheet.getRange(8, 1, 6, 3);
    range.setValues(values);

    // formulas are
    //=(100*countif(Data!RPM:RPM;0))/count(Data!RPM:RPM)
    //=NumIgnitions
    //=NumShortIgnitions
    //=sum(Data!GLIDE:GLIDE)/countif(Data!SPEED:SPEED, ">0")*100
    //=arrayformula(MAX(FREQUENCY(IF(Data!GLIDE:GLIDE=1,ROW(Data!GLIDE:GLIDE)),IF(Data!GLIDE:GLIDE<>1,ROW(Data!GLIDE:GLIDE)))))
    //=sqrt(sumsq(Data!BATTERY:BATTERY)/count(Data!BATTERY:BATTERY))    
    countShortIgnitions();    
    var values = [
      [ "=(100*countif(Data!" + RPM + ":" + RPM + ";0))/count(Data!" + RPM + ":" + RPM + ")" ],
      [ NumIgnitions ],
      [ NumShortIgnitions ],
      [ "=sum(Data!" + Glide + ":" + Glide + ")/countif(Data!" + OBDSpeed + ":" + OBDSpeed + "; \">0\")*100" ],
      [ "=arrayformula(MAX(FREQUENCY(IF(Data!" + Glide + ":" + Glide + "=1;ROW(Data!" + Glide + ":" + Glide + "));IF(Data!" + Glide + ":" + Glide + "<>1;ROW(Data!" + Glide + ":" + Glide + ")))))" ],
      [ "=sqrt(sumsq(Data!" + BattPackCurrent + ":" + BattPackCurrent + ")/count(Data!" + BattPackCurrent + ":" + BattPackCurrent + "))" ],
    ];
    var range = sheet.getRange(8, 2, 6, 1);
    range.setFormulas(values);
    range.setNumberFormat("0.00");
    
    printLog("Hybrid Analysis added");

    var values = [
      [ "Average Speed", "", "Km/h" ],
      [ "Top Speed", "", "Km/h" ],
      [ "Average Absolute Variation", "", "Speed variations during the trip (only while moving): measure your driving style" ],
    ];
    var range = sheet.getRange(15, 1, 3, 3);
    range.setValues(values);

    // formulas are
    //=AVERAGE(Data!SPEED:SPEED)
    //=Max(Data!SPEED:SPEED)
    //=sqrt(sumsq(Data!SPEEDVAR:SPEEDVAR)/countif(Data!SPEED:SPEED, ">0"))
    var values = [
      [ "=AVERAGE(Data!" + OBDSpeed + ":" + OBDSpeed + ")" ],
      [ "=Max(Data!" + OBDSpeed + ":" + OBDSpeed + ")" ],
      [ "=sqrt(sumsq(Data!" + SpeedVar + ":" + SpeedVar + ")/countif(Data!" + OBDSpeed + ":" + OBDSpeed + "; \">0\"))" ],
    ];
    var range = sheet.getRange(15, 2, 3, 1);
    range.setFormulas(values);
    range.setNumberFormat("0.00");
    
    sheet.autoResizeColumn(1);
    sheet.autoResizeColumn(2);
    sheet.autoResizeColumn(3);
    
    printLog("Analysis sheet added");
  }
  
  function insertSeparatorColumn() {
    var alreadyexist = findColumnByName("|");
    if (alreadyexist != -1) {
      return;
    }
    
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName("Data");
    var last = sheet.getLastColumn();
    sheet.insertColumnAfter(last);
    var cell = sheet.getRange(1, last + 1);
    cell.setValue("|");
    var rangeToCopy = sheet.getRange(1, last + 1, 1, 1);
    rangeToCopy.copyTo(sheet.getRange(2, last + 1, sheet.getLastRow() - 1, 1));
    sheet.autoResizeColumn(1);
    
    printLog("separator column added");
  }
  
  function insertSpeedVarColumn() {
    SpeedVar = findColumnByName(SpeedVarName);
    if (SpeedVar != -1) {
      return;
    }
    
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName("Data");
    var last = sheet.getLastColumn();
    sheet.insertColumnAfter(last);
    
    // first 2 cells are constant
    var values = [
      [ SpeedVarName ], 
      [ "0" ], 
    ];
    var range = sheet.getRange(1, last + 1, 2, 1);
    range.setValues(values);
      
    // formula is "=SPEED3-SPEED2"
    var cell = sheet.getRange(3, last + 1);
    cell.setFormula("=" + OBDSpeed + "3-" + OBDSpeed + "2");
      
    var rangeToCopy = sheet.getRange(3, last + 1, 1, 1);
    rangeToCopy.copyTo(sheet.getRange(3, last + 1, sheet.getLastRow() - 2, 1));

    SpeedVar = findColumnByName(SpeedVarName);      
    printLog("speed variation column added");
  }
      
  function insertGlideColumn() {
    Glide = findColumnByName(GlideName);
    if (Glide != -1) {
      return;
    }
      
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName("Data");
    var last = sheet.getLastColumn();
    sheet.insertColumnAfter(last);
      
    var range = sheet.getRange(1, last + 1, 1, 1);
    range.setValue(GlideName);
      
    // formula is "=if(and(RPM2<500;SPEED2>10;abs(BATTPACKCURRENT2)<5);1;0)"
    var cell = sheet.getRange(2, last + 1);
    cell.setFormula("=if(and(" + RPM + "2<500;" + OBDSpeed + "2>10;abs(" + BattPackCurrent + "2)<5);1;0)");
      
    var rangeToCopy = sheet.getRange(2, last + 1, 1, 1);
    rangeToCopy.copyTo(sheet.getRange(2, last + 1, sheet.getLastRow() - 1, 1));
      
    Glide = findColumnByName(GlideName);
    printLog("glide column added");
  }
      
  function activateSheetByName(name) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName(name);
    ss.setActiveSheet(sheet);
  }
      
  // returns only letter of the column with the given name in the first cell
  function findColumnByName(name) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName("Data");
    var last = sheet.getLastColumn();
    var foundcolumn = -1;
      
    for (var i = 1; i <= last; i++) {
      var cell = sheet.getRange(1, i);
      var value = cell.getValue();
      
      if (value == name) {
        foundcolumn = cell.getA1Notation();
        printLog("Found column " + name + " at " + foundcolumn);
      }
    }
    if (foundcolumn == -1) {
      printLog("Column " + name + " not found");
    }
    else {
      foundcolumn = foundcolumn.substring(0, foundcolumn.length - 1);
    }
      
    return foundcolumn;
  }

  // set "-" to "0" and check if there are values > max
  function sanitizeColumn(column, max) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheets()[0];
    var range = sheet.getRange(column + ":" + column );
    var height = range.getHeight();
    var values = range.getValues();
    var foundnull = false;
    
    printLog("checking " + height + " values at column " + column);

    for (var i = 0; i < height; ++i) {
      if (values[i] == "-") {
        var cell = range.getCell(i + 1, 1);
        cell.setValue(0);
        foundnull = true;
      }
      if (values[i] > max) {
        printLog("ERROR: Values in column " + column + " out of range, check for import errors");
      }
    }
    if (foundnull)
      printLog("some missing values in column " + column);
  }

  // set global vars to columns position
  function findNeededColumns() {
    OBDSpeed = findColumnByName(OBDSpeedName);
    RPM = findColumnByName(RPMName);
    BattPackCurrent = findColumnByName(BattPackCurrentName);
    SOC = findColumnByName(SOCName);
  }
  function sanitizeNeededColumns() {
    sanitizeColumn(OBDSpeed, 300);
    sanitizeColumn(RPM, 10000);
    sanitizeColumn(BattPackCurrent, 300);
    sanitizeColumn(SOC, 100);
  }

  // main

  addLogSheet();
  printLog("Begin data processing");
  setDataName();
  activateSheetByName("Data");
  findNeededColumns();
  sanitizeNeededColumns();
  insertSeparatorColumn();
    
  if (OBDSpeed != -1) {
    insertSpeedVarColumn();
  }
  else {
    printLog("ERROR: Could not add speed variance column");
  }
    
  if ((OBDSpeed != -1) && (RPM != -1) && (BattPackCurrent != -1)) {
    insertGlideColumn();
  }
  else {
    printLog("ERROR: Could not add glide column");
  }

  addAnalysisSheet();
    
  printLog("End data processing");
}

=== CUT HERE ===


Now select "File / Save" and then "Run / AnalyzeTorqueLogs"

You will have to authorize the script



After the script has finished running, switch back to the spreadsheet, and you'll see a new tab named "Analysis".


This first version compute some sample parameters regarding the HV battery:
start and end charge, and average value vs the value considered the best by some hypermilers (60%).

There are some other values that may answer some curiosity about the car inner working:
the percentage of the time the petrol engine was actually off during the trip,
the percentage of time the car was moving using very little energy (glide),
the longest glide time of the trip
a battery "stress" value, that evaluates how may amperes have flown in and out of the battery: a higher value means higher stress, but a meaningful range has yet to be established.

NOTE:
This new version add some parameters:
how many times ICE was turned on during the trip
how many ICE ignitions lasted less than 5 seconds (those are considered just a waste of fuel)
an evaluation of speed variance during the trip: this should give an idea of your driving stile (calm or aggressive).

Ignitions13.00Times ICE was turned on
Inefficient Ignitions1.00Times ICE was turned on for less than 5 seconds



Average Speed41.08
Top Speed77.00
Average Absolute Variation1.97Speed variations during the trip (only while moving)

2013-09-14

Rorschach Test

These are data of car speed at various RPMs.
Same road, different driving stile:
 

We always have 2 aggregation points:
one at 0 RPM, where we have the car running on electric power up to 70 km/h, and one at 1300 RPM, that seems to be the sweet spot of the engine.
Speedy driving leads to higher RPM and a wider distribution.
Use of EV mode, leads to higher RPM than normal: note the aggregation around 2100 and the gap between 1300 and 1600.

Is this the best possible use of a car and an iPad?


Did someone talked about gamification of the driving experience?

2013-09-13

Battery thief framed by app: all details inside

Following up from a battery draining problem, I've found a tool (BetterBatteryStats) that profiles battery usage in grater detail than the Android stock battery tool:

http://www.howtogeek.com/139592/how-to-find-the-root-cause-of-your-android-battery-problems/

Here is the profile of a full day plagued by anomalous battery consumption:


BetterBatteryStats has found RILJ to be the prime suspect:



It seems to be a known behavior as said here:
http://forum.xda-developers.com/showthread.php?p=31352333

http://forum.xda-developers.com/showthread.php?t=1878692
http://forum.xda-developers.com/showthread.php?p=31352333



I've followed the instruction and disabled Google geolocalization:


After some time running, RILJ is still top in battery usage, but it's weight is comparable to other processes, and battery consumption is a reasonable 1%/h



All went fine for some days, when after sending an SMS and receiving a call, the issue surfaced again.

http://code.google.com/p/android/issues/detail?id=17383

I tried disabling "increase volume when in pocket".




My phone is running fine since then.

2013-09-09

Shine on you, crazy Clio

Renault is my favorite target in these days.
Here is the Clio dashboard.
Some designer might have thought that chrome plated finish are sexy.
Truth is that no matter where the sun is, a ray will reflect exactly into your eyes.

2013-09-08

More car keys nonsense

This is a Renault credit card sized car key.
Probably the most uncomfortable key design ever.
You have to insert it in a slot to start the car, so you can't keep it in the wallet with your other cards.
It wouldn't be possible anyway because it's too thick.
It's even too big to stay comfortably in you pockets without fearing to break it every time you sit down.
Congrats Renault!

2013-09-05

Torque Game

Driving gamification is something I had in my mind for some time.
Torque seems to be a good starting point, so I asked on the Torque support forum for a plugin that can provide some data to play with.
No one answered, so far; so I began experimenting myself.
I'm collecting Torque logs on a known road trip, changing driving style from time to time, to build a library of trips.
Here are the first:
https://drive.google.com/folderview?id=0B8xG59QDgvQ3OS1SU3BVYVQxQTA&usp=sharing
I'm adding an Analysis tab where I'm experimenting with statistical functions that can measure a trip and give a score that can be compared with other trips to find the "perfect driving style".

There's a thread about this on the Hybrid Synergy Forum.

2013-09-04

The clock ticks on

Samsung unveiled the new Galaxy Gear Smartwatch.
Does someone still wear watches these days?
Does this mean that I'll have another device to charge every night with another different charger?
Fail or Feat?

2013-09-01

Metallic noise from the hood

While driving in EV mode on bumpy roads, I've heard some metallic noise coming from the hood.
At first, I thought it was the hood itself, but at a closer examination I've excluded it because it rests on rubber supports while closed.
Maybe today I've found the source of the noise.
There's a felt-like rigid sheet under the hood. It's bolted on all sides except one, where it can vibrate against the hood.
I've placed a small wooden spacer to keep it in place.
I'll see in the next days if the noise will vanish.