Coder Social home page Coder Social logo

row_range not working about django-pivot HOT 3 CLOSED

GarikFirst avatar GarikFirst commented on August 23, 2024
row_range not working

from django-pivot.

Comments (3)

martsberger avatar martsberger commented on August 23, 2024

It looks like maybe the documentation in the Readme is wrong. The first parameter to pivot is the row and the second parameter is the column. In order to fill in the date using row_range you'd want

row_range = [date(2022, 3, 28) + timedelta(days) for days in range(8)]
trackings = pivot(trackings, 'date', 'project', 'time', row_range=row_range)

from django-pivot.

GarikFirst avatar GarikFirst commented on August 23, 2024

Thank you for your very quick response!

Oh, I got the point - if I want to populate dates by row_range - date should always be first parameter (which is row).

I ended up with something like this

dates = [datetime.date(2022, 3, 28), datetime.date(2022, 3, 29), datetime.date(2022, 3, 30), datetime.date(
    2022, 3, 31), datetime.date(2022, 4, 1), datetime.date(2022, 4, 2), datetime.date(2022, 4, 3)]

tracks = [{'project': 1, '2022-03-28': datetime.timedelta(seconds=14400), '2022-03-29': None, '2022-03-30': None},
{'project': 2, '2022-03-28': datetime.timedelta(seconds=90), '2022-03-29': None, '2022-03-30': datetime.timedelta(seconds=3900)},
{'project': 3, '2022-03-28': None, '2022-03-29': datetime.timedelta(seconds=21600), '2022-03-30': None}]

for t in tracks:
    for d in dates:
        if str(d) not in t:
            t[str(d)] = None

And get list of dicts as I wanted (to easy iterate in Django template later):

[{'project': 1, '2022-03-28': datetime.timedelta(seconds=14400), '2022-03-29': None, '2022-03-30': None, '2022-03-31': None, '2022-04-01': None, '2022-04-02': None, '2022-04-03': None}, {'project': 2, '2022-03-28': datetime.timedelta(seconds=90), '2022-03-29': None, '2022-03-30': datetime.timedelta(seconds=3900), '2022-03-31': None, '2022-04-01': None, '2022-04-02': None, '2022-04-03': None}, {'project': 3, '2022-03-28': None, '2022-03-29': datetime.timedelta(seconds=21600), '2022-03-30': None, '2022-03-31': None, '2022-04-01': None, '2022-04-02': None, '2022-04-03': None}]

from django-pivot.

GarikFirst avatar GarikFirst commented on August 23, 2024

As designed

from django-pivot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.