Skip to content
Snippets Groups Projects

Addition of Google Map API , Trees and Train data and End points for the same.

Merged Saisankar Gochhayat requested to merge saisankargochhayat/CarbonFootprint-API:tree into master
8 unresolved threads

This MR addresses issue #18 (closed) , #16 (closed) ,#15 (closed) .

  1. This includes data for trees from extension , db script for it and the endpoint for it.
  2. Trains data also has been added to the raw data and the db script for the same has been made.
  3. The trains route and trees route has been added to the routes handler.
  4. Documentation and test cases has been updated accordingly.

Merge request reports

Approved by

Merged by Chirag AroraChirag Arora 7 years ago (Jul 5, 2017 11:29pm UTC)

Merge details

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
65 65 for (let i = 0; i < numOfComponents; i++) {
66 66 if(item.components[i].quantity.length > 1){
67 67 let getInterpolatedQuantity = await interpolate(item.quantity, item.components[i].quantity, quantity);
68 console.log(`Interpolated value = ${getInterpolatedQuantity}`)
68 console.log(`Interpolated value = ${getInterpolatedQuantity}`);
  • Just wondering what order of interpolation are we using?

  • Liner Interpolation , for the dataset we have this seems to work more accurately than other order of interpolations.

  • but if you have more data points. Linear interpolation doesn't takes those into account. Then how is it more accurate? I think we should use a computation library to get more accurate results.

  • Everpolate is something that we had in mind , for polynomial interpolation. How ever it does not support extrapolation and the kind of data it takes in the extrapolation example is not supported in our schema. And the linear regression offered in this library has been essentially implemented in our function. http://borischumichev.github.io/everpolate/#poly

  • Extrapolation, doesn't matter what method you use, is always ambiguous. Now, there is a difference between linear interpolation and linear regression. Linear interpolation finds a point between two points joined by a straight line. Whereas, Linear regression finds a point on a straight line whose slope depends on many points.

    See the picture below. The brown line is the linear regression of the data represented by blue circles. Whereas linear interpolation would be joining each consecutive point with a straight line(a polynomial). The second picture shows polynomial interpolation. Clearly, polynomial is more accurate than regression. So, I think it's better to go with polynomial interpolation if the data lies in between. I would also like @bruno-wp to share his views.

    Linear Regression: Screen_Shot_2017-06-29_at_15.41.53

    Interpolation: Screen_Shot_2017-06-29_at_03.25.44

    Edited by Chirag Arora
  • @heychirag we just did some calculations using polynomial interpolation and the results are really bad. Have a look at https://runkit.com/embed/rjcp7jlnzk0i. I think we need to have more data points to get the results that are actually useful.

  • Here is the linear interpolation result for reference. https://runkit.com/embed/9qpyhf7lppy7

  • So the method in the 2nd figure is not actually polynomial interpolation. Sorry for this. It's actually more closer to either spline or pchip interpolation. The following interpolated results have been calculated using MATLAB for the same data set and test point(2720).

    • linear interpolation: 14789.68
    • spline interpolation: 14794.34
    • pchip interpolation: 14794.22
    • linear regression: 14899.14

    pchip and spline can be well used for extrapolation too.

    extrapolation using pchip: Screen_Shot_2017-06-29_at_13.01.58

    extrapolation using spline: Screen_Shot_2017-06-29_at_13.02.18

    The best method depends on the type of data we are dealing with. If we are dealing with data about which we are certain is a non-linear function, then it is better to go with spline or pchip. Here is a good answer that differentiates when to use interpolation and when to use regression.

    So if we decide to stick with regression, then I would suggest you to change all the function names because it's quite misleading.

    Edited by Chirag Arora
  • @heychirag we are actually using linear interpolation and not linear regression.

  • Linear Regression yields some inaccurate values in the lower range even: https://runkit.com/embed/3xjfg2cfrrz5

  • And the linear regression offered in this library has been essentially implemented in our function.

    With reference to above, I was under the impression that we were were using linear regression.

    So if we are using linear interpolation, then I would recommend to instead go for spline or pchip interpolation. You can clearly see the difference between spline/pchip and linear interpolation.

    Screen_Shot_2017-06-30_at_15.30.55

    Edited by Chirag Arora
  • I have replaced linear interpolation with spline interpolation.

  • Please register or sign in to reply
  • 101 101 obj.region="Default";
    102 102 obj.quantity=[1];
    103 103 obj.unit="kg";
    104 obj.categories=["flights"];
    104 obj.categories=["flights","transport"];
    • Did we decide to use flights as generic transport? I might have missed some conversations before.

    • I didn't get your question , this is just the categories so that if we need we can query and aggregate related stuff.

    • The idea here is that this piece of data should belong both to the "flights" category and to the "transport" category.

      On the one hand, this makes sense, since flights are a form of transport.

      On the other hand, I wonder if adding both the category and its super-categories in all pieces of data that belong to that category is an efficient way to organize the sub-categorization information. It seems redundant. It should suffice to describe once that "flights" is a sub-category of "transport".

      This is not a new problem in computer science. There is whole field of research concerned about this. Google "Ontology", "Decription Logics", and so on...

      Anyway, these concerns are a little bit beyond the scope of our project for now. So, choose whatever feels more natural for you, and let's worry about this later only if it becomes a problem.

    • Please register or sign in to reply
  • 9 "quantity" : [1],
    10 "unit" : "kg/km",
    11 "M.F.(multiply factor)" : 443
    12 },
    13 "frieght" : {
    14 "C02" : 0.0191,
    15 "NO2" : 0,
    16 "CH4" : 0,
    17 "region" : "Default",
    18 "category" : "transport",
    19 "method" : "simple",
    20 "quantity" : [1],
    21 "unit" : "kg/km",
    22 "M.F.(multiply factor)" : 1225
    23 },
    24 "intercités" : {
  • 31 "quantity" : [1],
    32 "unit" : "kg/km",
    33 "M.F.(multiply factor)" : 992
    34 },
    35 "tgv" : {
    36 "C02" : 0.0032,
    37 "NO2" : 0,
    38 "CH4" : 0,
    39 "region" : "France",
    40 "category" : "transport",
    41 "method" : "simple",
    42 "quantity" : [1],
    43 "unit" : "kg/km",
    44 "M.F.(multiply factor)" : 516
    45 },
    46 "tgv lyria" : {
  • Hi @Everyone! Just a general comment, as I haven't had time to look into this MR in detail yet. I noticed that this MR addresses several issues (and quite unrelated issues: trains, trees, ...). I strongly recommend that, in the future, you try to submit smaller MRs, and one MR per issue. This has several advantages, including the following:

    1. it reduces MR reviewing and acceptance time

    2. if you submit a single MR for two issues, a good solution for one of the issues might be blocked, if the MR gets stuck because the reviewers think that it doesn't solve the other issue properly. If 2 separate MRs had been submitted, the one containing the good solution could be accepted quickly.

    3. the ability to submit separate and independent MRs is also an indication that your code is modular and capable of scaling independently in different directions. If you only submit big MRs that solve several issues at once, this may be an indication that your code is becoming too monolithic, with interdependencies that prevent independent MRs.

  • added 1 commit

    Compare with previous version

  • 174 "quantity" : [1],
    175 "unit" : "kg/km",
    176 "M.F.(multiply factor)" : 425
    177 },
    178 "railcars india" : {
    179 "C02" : 0.0412,
    180 "NO2" : 0,
    181 "CH4" : 0,
    182 "region" : "India",
    183 "category" : "transport",
    184 "method" : "simple",
    185 "quantity" : [1],
    186 "unit" : "kg/km",
    187 "M.F.(multiply factor)" : 1240
    188 },
    189 "freight india" : {
  • added 1 commit

    Compare with previous version

  • added 1 commit

    • ab98ef1b - interpolation changed from linear to spline

    Compare with previous version

  • This MR has conflicts. Could you solve them, so that we can approve it?

  • 104 100 });
    105 101 }
    106 102
    107 exports.calculate = async function(a, b, c){
    103 exports.calculate = async function(a, b, c, d = 1){
  • 1 {
    2 "railcars" : {
    3 "C02" : 0.0412,
    4 "NO2" : 0,
    5 "CH4" : 0,
    6 "region" : "Default",
    7 "category" : "transport",
    8 "method" : "simple",
    9 "quantity" : [1],
    10 "unit" : "kg/km",
    11 "M.F.(multiply factor)" : 443
    12 },
    13 "frieght" : {
  • Bruno
    Bruno @bruno-wp started a thread on the diff
  • 109 109 done();
    110 110 });
    111 111 });
    112
  • Bruno approved this merge request

    approved this merge request

  • added 1 commit

    • 1ad26e63 - added tree test case , changed freight spelling and controller parameter names

    Compare with previous version

  • added 19 commits

    Compare with previous version

  • @bruno-wp @Kolpa @heychirag The merge conflicts are resolved and the changed required are incorporated.

  • Bruno approved this merge request

    approved this merge request

  • Chirag Arora approved this merge request

    approved this merge request

  • Chirag Arora mentioned in commit c05ea726

    mentioned in commit c05ea726

  • merged

  • Please register or sign in to reply
    Loading