Community Portal

Add units to the visualisations

Created on Thursday 10 June 2021, 08:59

Back to task list
  • ID
    991921
  • Project
    Metabolism of Cities Data Hub
  • Status
    Completed
  • Priority
    Medium
  • Type
    Programming work
  • Tags
    Data Hub Priority Plan 2021 General data hub improvements
  • Assigned to
    Guus Hoekman
  • Subscribers
    Carolin Bellstedt
    Guus Hoekman
    Paul Hoekman

You are not logged in

Log In Register

Please join us and let's build things, together!

Description

(Not sure if this counts as a "feature request", but I'm making it a task for now:)
At the moment, the various charts of the visualisations (which are based on highcharts) don't display any units, but simply "values", see this example. The unit is not shown anywhere in the diagram, in the table view, yes, there is the column, but just looking at any one of the graphics or hovering over them to get the value, you can't know what it is.
In the example, it is kg, but only says so in the description and table.

A user should be able to see if it is g, kg, tonnes, MJ etc. This is also especially relevant when the file is downloaded and detached from any additional info.

Discussion and updates


New task was created


Task was assigned to Guus Hoekman


Status change: Open → In Progress


Hi both, this sounds like a trivial thing but it requires some other work that is not necessarily trivial. I have created a task here Guus in case you want to give it a shot... but this is mostly back-end work, might be most efficient to wait for some back-end programming work to be available.

BTW a quick hack here is to run a query to check the underlying units of the entire datasets. Something like this:

units = Data.objects.filter(dataset=id).values("unit").distinct()

Then you check:

if units.count == 1:

And if that is the case, then you can just use the unit that is returned. But if it's > 1, then you shouldn't -- then the other task needs to be done.

Last edited: 2021-10-09 14:42:43.787303+00:00


Thanks for your input Paul and the somehow not surprising news that this isn't trivial.

Sounds like the quick hack is the way to go for now then, especially for the CityLoops data and SCA reports, as the units used by the cities should be the same within one dataset.


Haha yeah if it was trivial I'd added that a while ago. In any case Guus please go ahead with this workaround but please add comments in your code to make it clear that this is not to be kept there in the long term.


@Paul I've tried implementing your quick hack but am not succeeding. Line 406 of library/views.py:

units = Data.objects.filter(id=id).values("unit").distinct()

But then if I loop through all the units later all I get is 15, regardless of the library item. I checked in the database which unit has the ID 15, and it's... "unit". So there's something not going right, maybe with the .values("unit") part?


Jeje yeah when I said "something like this" I meant to convey the general concept... that was not code I wrote for production.

Anyways I fixed the code, see views.py, should work now.


Thanks Paul. This is now implemented. I noticed that sometimes it doesn't work perfectly. For example, with a population dataset it lists the unit as "item". Also, when a single row is missing a unit it will not recognise them all as the same and it won't show a single unit (even though it seems as if it only uses one unit in the rows that do have a unit.

But since it's a quick hack I think this is fine until we have a proper solution for it.


Status change: In Progress → Completed


Got it. And yeah people is actually not a unit, so that is why it records as ITEM. But in the front end we might improve that yeah ;-)
If you want you can create tasks for these things and I will try look at that in due course. But glad it's sorted for now.