How add 0 when TruncWeek's week no result in Django Query? - django

I want query the issue's count of group by weekly.
query1 = MyModel.object.filter(issue_creator__in=group.user_set.all()).\
annotate(week=TruncWeek('issue_creat_date')).values('week').annotate(count=Count('id')).order_by('week'))
the query result is OK. the queryset result:
[
{'week': datetime.datetime(2022, 1, 3, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 9},
{'week': datetime.datetime(2022, 1, 10, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 12},
{'week': datetime.datetime(2022, 1, 17, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 10},
{'week': datetime.datetime(2022, 2, 7, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 1},
{'week': datetime.datetime(2022, 2, 14, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 6},
{'week': datetime.datetime(2022, 2, 21, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 11},
{'week': datetime.datetime(2022, 2, 28, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 1}
]
but 20220101-20220301 has 9 weeks:
[
datetime.datetime(2022, 1, 3, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>),
datetime.datetime(2022, 1, 10, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>),
datetime.datetime(2022, 1, 17, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>),
datetime.datetime(2022, 1, 24, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>),
datetime.datetime(2022, 1, 31, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>),
datetime.datetime(2022, 2, 7, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>),
datetime.datetime(2022, 2, 14, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>),
datetime.datetime(2022, 2, 21, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>),
datetime.datetime(2022, 2, 28, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>)
]
I want add zero when that week no result as this result:
[
{'week': datetime.datetime(2022, 1, 3, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 9},
{'week': datetime.datetime(2022, 1, 10, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 12},
{'week': datetime.datetime(2022, 1, 17, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 10},
{'week': datetime.datetime(2022, 1, 24, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 0},
{'week': datetime.datetime(2022, 1, 31, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 0},
{'week': datetime.datetime(2022, 2, 7, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 1},
{'week': datetime.datetime(2022, 2, 14, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 6},
{'week': datetime.datetime(2022, 2, 21, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 11},
{'week': datetime.datetime(2022, 2, 28, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>), 'count': 1}
]
how to write the right queryset?
Thanks.

Django method for None value Coalesce.
from django.db.models.functions import Coalesce
query1 = MyModel.object.filter(issue_creator__in=group.user_set.all()).\
annotate(week=TruncWeek('issue_creat_date')).values('week').annotate(count=Count('id')).order_by('week'))

Related

Django ORM queryset equivalent to group by year-month?

I have an Django app and need some datavisualization and I am blocked with ORM.
I have a models Orders with a field created_at and I want to present data with a diagram bar (number / year-month) in a dashboard template.
So I need to aggregate/annotate data from my model but did find a complete solution.
I find partial answer with TruncMonth and read about serializers but wonder if there is a simpliest solution with Django ORM possibilities...
In Postgresql it would be:
SELECT date_trunc('month',created_at), count(order_id) FROM "Orders" GROUP BY date_trunc('month',created_at) ORDER BY date_trunc('month',created_at);
"2021-01-01 00:00:00+01" "2"
"2021-02-01 00:00:00+01" "3"
"2021-03-01 00:00:00+01" "3"
...
example
1 "2021-01-04 07:42:03+01"
2 "2021-01-24 13:59:44+01"
3 "2021-02-06 03:29:11+01"
4 "2021-02-06 08:21:15+01"
5 "2021-02-13 10:38:36+01"
6 "2021-03-01 12:52:22+01"
7 "2021-03-06 08:04:28+01"
8 "2021-03-11 16:58:56+01"
9 "2022-03-25 21:40:10+01"
10 "2022-04-04 02:12:29+02"
11 "2022-04-13 08:24:23+02"
12 "2022-05-08 06:48:25+02"
13 "2022-05-19 15:40:12+02"
14 "2022-06-01 11:29:36+02"
15 "2022-06-05 02:15:05+02"
16 "2022-06-05 03:08:22+02"
expected result
[
{
"year-month": "2021-01",
"number" : 2
},
{
"year-month": "2021-03",
"number" : 3
},
{
"year-month": "2021-03",
"number" : 3
},
{
"year-month": "2021-03",
"number" : 1
},
{
"year-month": "2021-04",
"number" : 2
},
{
"year-month": "2021-05",
"number" : 3
},
{
"year-month": "2021-06",
"number" : 3
},
]
I have done this but I am not able to order by date:
Orders.objects.annotate(month=TruncMonth('created_at')).values('month').annotate(number=Count('order_id')).values('month', 'number').order_by()
<SafeDeleteQueryset [
{'month': datetime.datetime(2022, 3, 1, 0, 0, tzinfo=<UTC>), 'number': 4},
{'month': datetime.datetime(2022, 6, 1, 0, 0, tzinfo=<UTC>), 'number': 2},
{'month': datetime.datetime(2022, 5, 1, 0, 0, tzinfo=<UTC>), 'number': 1},
{'month': datetime.datetime(2022, 1, 1, 0, 0, tzinfo=<UTC>), 'number': 5},
{'month': datetime.datetime(2021, 12, 1, 0, 0, tzinfo=<UTC>), 'number': 1},
{'month': datetime.datetime(2022, 7, 1, 0, 0, tzinfo=<UTC>), 'number': 1},
{'month': datetime.datetime(2021, 9, 1, 0, 0, tzinfo=<UTC>), 'number': 2},
'...(remaining elements truncated)...'
]>
Try adding the order_by on the original field if you have multi-year data.
from django.db.models import Sum
from django.db.models.functions import TruncMonth
Orders.objects.values(month=TruncMonth('created_at')).
order_by("created_at").annotate(Sum('number')

Looking for applications of BDDs to problems involving x,y concept

I am looking at the applications of BDD to figure out if it's possible to implement the x,y concept there.
Let me explain.
Let's say I have z of something to distribute in an x,y coordinate plane. The constraints are:
All the z items have to be placed in the x,y coordinate plane.
Some of the z items have to be a certain distance away from each other.
I think integer linear programming can sort this out. For example, with a set of equations, I can represent the constraints above and do linear programming to solve for the exact locations.
But what I am asking is if BDD can help with this?
In other words, can Binary Decision Diagram represent x,y coordinates and can I represent the above constraints with Boolean functions (equivalent to the set of equations above) and BDDs be manipulated to sort out the above constraints for exact locations just like linear programming?
I do not have any concrete examples to show but I think representing x,y coordinates equivalent in Binary is a place to start?
Yes, it is possible to encode the given integer-valued problem of placement over a plane using binary decision diagrams, and thus compute answers (as satisfying assignments). For example, using the Python package omega (which uses the Python package dd for BDD computations):
from omega.symbolic import fol
fol = _fol.Context()
# Register integer-valued variables, with ranges of representation using BDDs
fol.declare(x1=(0, 11), y1=(0, 11), x2=(0, 11), y2=(0, 11))
# Encode the problem:
#
# Two points on a Euclidean plane are represented by their Cartesian coordinates
# `x1, y1` and `x2, y2`.
# Each point is in the square mesh `x \in 1..10 /\ y \in 1..10`.
#
# Note that the variables are declared with larger domains,
# in order to ensure that this boundary constraint is representable with the
# resulting BDDs.
#
# The distance between the two points should be the square root of 10.
expr = r'''
(x1 >= 1) /\ (x1 <= 10)
/\ (x2 >= 1) /\ (x2 <= 10)
/\ (y1 >= 1) /\ (y1 <= 10)
/\ (y2 >= 1) /\ (y1 <= 10)
/\ (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) = 10
'''
# Solve the problem, by adding creating a BDD for it
u = fol.add_expr(expr)
# Enumerate all solutions (i.e., all satisfying assignments)
# These are all the pairs of points within the box mesh x \in 1..10 /\ y \in 1..10
# that have a distance equal to the square root of 10.
assignments = list(fol.pick_iter(u))
print(assignments)
Using BDDs with distance constraints as above can lead to BDDs that are exponential in size in the number of variables. The reason is that representing multiplication can lead to exponentially-sized BDDs, as proved in https://doi.org/10.1109/12.73590 .
If the constraints are not distance between points, but distance along each axis (i.e., an inequality or equality constraint on the absolute value of x1 - x2 or y1 - y2, or on both), then exponential complexity is avoided.
The above solves the placement problem over a mesh. This is a discrete placement problem. The continuous placement problem cannot be solved with binary decision diagrams, because it requires floating-point arithmetic.
The program above prints:
[{'x1': 4, 'y1': 5, 'x2': 1, 'y2': 4},
{'x1': 4, 'y1': 9, 'x2': 1, 'y2': 8},
{'x1': 4, 'y1': 3, 'x2': 1, 'y2': 4},
{'x1': 4, 'y1': 7, 'x2': 1, 'y2': 8},
{'x1': 4, 'y1': 1, 'x2': 1, 'y2': 2},
{'x1': 4, 'y1': 5, 'x2': 1, 'y2': 6},
{'x1': 4, 'y1': 9, 'x2': 1, 'y2': 10},
{'x1': 4, 'y1': 3, 'x2': 1, 'y2': 2},
{'x1': 4, 'y1': 7, 'x2': 1, 'y2': 6},
{'x1': 4, 'y1': 4, 'x2': 1, 'y2': 5},
{'x1': 4, 'y1': 8, 'x2': 1, 'y2': 9},
{'x1': 4, 'y1': 2, 'x2': 1, 'y2': 1},
{'x1': 4, 'y1': 6, 'x2': 1, 'y2': 5},
{'x1': 4, 'y1': 10, 'x2': 1, 'y2': 9},
{'x1': 4, 'y1': 4, 'x2': 1, 'y2': 3},
{'x1': 4, 'y1': 8, 'x2': 1, 'y2': 7},
{'x1': 4, 'y1': 2, 'x2': 1, 'y2': 3},
{'x1': 4, 'y1': 6, 'x2': 1, 'y2': 7},
{'x1': 4, 'y1': 10, 'x2': 1, 'y2': 11},
{'x1': 4, 'y1': 1, 'x2': 5, 'y2': 4},
{'x1': 4, 'y1': 5, 'x2': 5, 'y2': 8},
{'x1': 4, 'y1': 9, 'x2': 5, 'y2': 12},
{'x1': 4, 'y1': 7, 'x2': 5, 'y2': 4},
{'x1': 4, 'y1': 5, 'x2': 5, 'y2': 2},
{'x1': 4, 'y1': 9, 'x2': 5, 'y2': 6},
{'x1': 4, 'y1': 3, 'x2': 5, 'y2': 6},
{'x1': 4, 'y1': 7, 'x2': 5, 'y2': 10},
{'x1': 4, 'y1': 4, 'x2': 5, 'y2': 1},
{'x1': 4, 'y1': 8, 'x2': 5, 'y2': 5},
{'x1': 4, 'y1': 2, 'x2': 5, 'y2': 5},
{'x1': 4, 'y1': 6, 'x2': 5, 'y2': 9},
{'x1': 4, 'y1': 10, 'x2': 5, 'y2': 13},
{'x1': 4, 'y1': 4, 'x2': 5, 'y2': 7},
{'x1': 4, 'y1': 8, 'x2': 5, 'y2': 11},
{'x1': 4, 'y1': 6, 'x2': 5, 'y2': 3},
{'x1': 4, 'y1': 10, 'x2': 5, 'y2': 7},
{'x1': 2, 'y1': 1, 'x2': 1, 'y2': 4},
{'x1': 2, 'y1': 5, 'x2': 1, 'y2': 8},
{'x1': 2, 'y1': 9, 'x2': 1, 'y2': 12},
{'x1': 2, 'y1': 7, 'x2': 1, 'y2': 4},
{'x1': 2, 'y1': 5, 'x2': 1, 'y2': 2},
{'x1': 2, 'y1': 9, 'x2': 1, 'y2': 6},
{'x1': 2, 'y1': 3, 'x2': 1, 'y2': 6},
{'x1': 2, 'y1': 7, 'x2': 1, 'y2': 10},
{'x1': 2, 'y1': 4, 'x2': 1, 'y2': 1},
{'x1': 2, 'y1': 8, 'x2': 1, 'y2': 5},
{'x1': 2, 'y1': 2, 'x2': 1, 'y2': 5},
{'x1': 2, 'y1': 6, 'x2': 1, 'y2': 9},
{'x1': 2, 'y1': 10, 'x2': 1, 'y2': 13},
{'x1': 2, 'y1': 4, 'x2': 1, 'y2': 7},
{'x1': 2, 'y1': 8, 'x2': 1, 'y2': 11},
{'x1': 2, 'y1': 6, 'x2': 1, 'y2': 3},
{'x1': 2, 'y1': 10, 'x2': 1, 'y2': 7},
{'x1': 2, 'y1': 5, 'x2': 5, 'y2': 4},
{'x1': 2, 'y1': 9, 'x2': 5, 'y2': 8},
{'x1': 2, 'y1': 3, 'x2': 5, 'y2': 4},
{'x1': 2, 'y1': 7, 'x2': 5, 'y2': 8},
{'x1': 2, 'y1': 1, 'x2': 5, 'y2': 2},
{'x1': 2, 'y1': 5, 'x2': 5, 'y2': 6},
{'x1': 2, 'y1': 9, 'x2': 5, 'y2': 10},
{'x1': 2, 'y1': 3, 'x2': 5, 'y2': 2},
{'x1': 2, 'y1': 7, 'x2': 5, 'y2': 6},
{'x1': 2, 'y1': 4, 'x2': 5, 'y2': 5},
{'x1': 2, 'y1': 8, 'x2': 5, 'y2': 9},
{'x1': 2, 'y1': 2, 'x2': 5, 'y2': 1},
{'x1': 2, 'y1': 6, 'x2': 5, 'y2': 5},
{'x1': 2, 'y1': 10, 'x2': 5, 'y2': 9},
{'x1': 2, 'y1': 4, 'x2': 5, 'y2': 3},
{'x1': 2, 'y1': 8, 'x2': 5, 'y2': 7},
{'x1': 2, 'y1': 2, 'x2': 5, 'y2': 3},
{'x1': 2, 'y1': 6, 'x2': 5, 'y2': 7},
{'x1': 2, 'y1': 10, 'x2': 5, 'y2': 11},
{'x1': 6, 'y1': 1, 'x2': 5, 'y2': 4},
{'x1': 6, 'y1': 5, 'x2': 5, 'y2': 8},
{'x1': 6, 'y1': 9, 'x2': 5, 'y2': 12},
{'x1': 6, 'y1': 7, 'x2': 5, 'y2': 4},
{'x1': 6, 'y1': 5, 'x2': 5, 'y2': 2},
{'x1': 6, 'y1': 9, 'x2': 5, 'y2': 6},
{'x1': 6, 'y1': 3, 'x2': 5, 'y2': 6},
{'x1': 6, 'y1': 7, 'x2': 5, 'y2': 10},
{'x1': 6, 'y1': 4, 'x2': 5, 'y2': 1},
{'x1': 6, 'y1': 8, 'x2': 5, 'y2': 5},
{'x1': 6, 'y1': 2, 'x2': 5, 'y2': 5},
{'x1': 6, 'y1': 6, 'x2': 5, 'y2': 9},
{'x1': 6, 'y1': 10, 'x2': 5, 'y2': 13},
{'x1': 6, 'y1': 4, 'x2': 5, 'y2': 7},
{'x1': 6, 'y1': 8, 'x2': 5, 'y2': 11},
{'x1': 6, 'y1': 6, 'x2': 5, 'y2': 3},
{'x1': 6, 'y1': 10, 'x2': 5, 'y2': 7},
{'x1': 4, 'y1': 1, 'x2': 3, 'y2': 4},
{'x1': 4, 'y1': 5, 'x2': 3, 'y2': 8},
{'x1': 4, 'y1': 9, 'x2': 3, 'y2': 12},
{'x1': 4, 'y1': 7, 'x2': 3, 'y2': 4},
{'x1': 4, 'y1': 5, 'x2': 3, 'y2': 2},
{'x1': 4, 'y1': 9, 'x2': 3, 'y2': 6},
{'x1': 4, 'y1': 3, 'x2': 3, 'y2': 6},
{'x1': 4, 'y1': 7, 'x2': 3, 'y2': 10},
{'x1': 4, 'y1': 4, 'x2': 3, 'y2': 1},
{'x1': 4, 'y1': 8, 'x2': 3, 'y2': 5},
{'x1': 4, 'y1': 2, 'x2': 3, 'y2': 5},
{'x1': 4, 'y1': 6, 'x2': 3, 'y2': 9},
{'x1': 4, 'y1': 10, 'x2': 3, 'y2': 13},
{'x1': 4, 'y1': 4, 'x2': 3, 'y2': 7},
{'x1': 4, 'y1': 8, 'x2': 3, 'y2': 11},
{'x1': 4, 'y1': 6, 'x2': 3, 'y2': 3},
{'x1': 4, 'y1': 10, 'x2': 3, 'y2': 7},
{'x1': 4, 'y1': 5, 'x2': 7, 'y2': 4},
{'x1': 4, 'y1': 9, 'x2': 7, 'y2': 8},
{'x1': 4, 'y1': 3, 'x2': 7, 'y2': 4},
{'x1': 4, 'y1': 7, 'x2': 7, 'y2': 8},
{'x1': 4, 'y1': 1, 'x2': 7, 'y2': 2},
{'x1': 4, 'y1': 5, 'x2': 7, 'y2': 6},
{'x1': 4, 'y1': 9, 'x2': 7, 'y2': 10},
{'x1': 4, 'y1': 3, 'x2': 7, 'y2': 2},
{'x1': 4, 'y1': 7, 'x2': 7, 'y2': 6},
{'x1': 4, 'y1': 4, 'x2': 7, 'y2': 5},
{'x1': 4, 'y1': 8, 'x2': 7, 'y2': 9},
{'x1': 4, 'y1': 2, 'x2': 7, 'y2': 1},
{'x1': 4, 'y1': 6, 'x2': 7, 'y2': 5},
{'x1': 4, 'y1': 10, 'x2': 7, 'y2': 9},
{'x1': 4, 'y1': 4, 'x2': 7, 'y2': 3},
{'x1': 4, 'y1': 8, 'x2': 7, 'y2': 7},
{'x1': 4, 'y1': 2, 'x2': 7, 'y2': 3},
{'x1': 4, 'y1': 6, 'x2': 7, 'y2': 7},
{'x1': 4, 'y1': 10, 'x2': 7, 'y2': 11},
{'x1': 2, 'y1': 1, 'x2': 3, 'y2': 4},
{'x1': 2, 'y1': 5, 'x2': 3, 'y2': 8},
{'x1': 2, 'y1': 9, 'x2': 3, 'y2': 12},
{'x1': 2, 'y1': 7, 'x2': 3, 'y2': 4},
{'x1': 2, 'y1': 5, 'x2': 3, 'y2': 2},
{'x1': 2, 'y1': 9, 'x2': 3, 'y2': 6},
{'x1': 2, 'y1': 3, 'x2': 3, 'y2': 6},
{'x1': 2, 'y1': 7, 'x2': 3, 'y2': 10},
{'x1': 2, 'y1': 4, 'x2': 3, 'y2': 1},
{'x1': 2, 'y1': 8, 'x2': 3, 'y2': 5},
{'x1': 2, 'y1': 2, 'x2': 3, 'y2': 5},
{'x1': 2, 'y1': 6, 'x2': 3, 'y2': 9},
{'x1': 2, 'y1': 10, 'x2': 3, 'y2': 13},
{'x1': 2, 'y1': 4, 'x2': 3, 'y2': 7},
{'x1': 2, 'y1': 8, 'x2': 3, 'y2': 11},
{'x1': 2, 'y1': 6, 'x2': 3, 'y2': 3},
{'x1': 2, 'y1': 10, 'x2': 3, 'y2': 7},
{'x1': 6, 'y1': 5, 'x2': 3, 'y2': 4},
{'x1': 6, 'y1': 9, 'x2': 3, 'y2': 8},
{'x1': 6, 'y1': 3, 'x2': 3, 'y2': 4},
{'x1': 6, 'y1': 7, 'x2': 3, 'y2': 8},
{'x1': 6, 'y1': 1, 'x2': 3, 'y2': 2},
{'x1': 6, 'y1': 5, 'x2': 3, 'y2': 6},
{'x1': 6, 'y1': 9, 'x2': 3, 'y2': 10},
{'x1': 6, 'y1': 3, 'x2': 3, 'y2': 2},
{'x1': 6, 'y1': 7, 'x2': 3, 'y2': 6},
{'x1': 6, 'y1': 4, 'x2': 3, 'y2': 5},
{'x1': 6, 'y1': 8, 'x2': 3, 'y2': 9},
{'x1': 6, 'y1': 2, 'x2': 3, 'y2': 1},
{'x1': 6, 'y1': 6, 'x2': 3, 'y2': 5},
{'x1': 6, 'y1': 10, 'x2': 3, 'y2': 9},
{'x1': 6, 'y1': 4, 'x2': 3, 'y2': 3},
{'x1': 6, 'y1': 8, 'x2': 3, 'y2': 7},
{'x1': 6, 'y1': 2, 'x2': 3, 'y2': 3},
{'x1': 6, 'y1': 6, 'x2': 3, 'y2': 7},
{'x1': 6, 'y1': 10, 'x2': 3, 'y2': 11},
{'x1': 6, 'y1': 1, 'x2': 7, 'y2': 4},
{'x1': 6, 'y1': 5, 'x2': 7, 'y2': 8},
{'x1': 6, 'y1': 9, 'x2': 7, 'y2': 12},
{'x1': 6, 'y1': 7, 'x2': 7, 'y2': 4},
{'x1': 6, 'y1': 5, 'x2': 7, 'y2': 2},
{'x1': 6, 'y1': 9, 'x2': 7, 'y2': 6},
{'x1': 6, 'y1': 3, 'x2': 7, 'y2': 6},
{'x1': 6, 'y1': 7, 'x2': 7, 'y2': 10},
{'x1': 6, 'y1': 4, 'x2': 7, 'y2': 1},
{'x1': 6, 'y1': 8, 'x2': 7, 'y2': 5},
{'x1': 6, 'y1': 2, 'x2': 7, 'y2': 5},
{'x1': 6, 'y1': 6, 'x2': 7, 'y2': 9},
{'x1': 6, 'y1': 10, 'x2': 7, 'y2': 13},
{'x1': 6, 'y1': 4, 'x2': 7, 'y2': 7},
{'x1': 6, 'y1': 8, 'x2': 7, 'y2': 11},
{'x1': 6, 'y1': 6, 'x2': 7, 'y2': 3},
{'x1': 6, 'y1': 10, 'x2': 7, 'y2': 7},
{'x1': 8, 'y1': 5, 'x2': 5, 'y2': 4},
{'x1': 8, 'y1': 9, 'x2': 5, 'y2': 8},
{'x1': 8, 'y1': 3, 'x2': 5, 'y2': 4},
{'x1': 8, 'y1': 7, 'x2': 5, 'y2': 8},
{'x1': 8, 'y1': 1, 'x2': 5, 'y2': 2},
{'x1': 8, 'y1': 5, 'x2': 5, 'y2': 6},
{'x1': 8, 'y1': 9, 'x2': 5, 'y2': 10},
{'x1': 8, 'y1': 3, 'x2': 5, 'y2': 2},
{'x1': 8, 'y1': 7, 'x2': 5, 'y2': 6},
{'x1': 8, 'y1': 4, 'x2': 5, 'y2': 5},
{'x1': 8, 'y1': 8, 'x2': 5, 'y2': 9},
{'x1': 8, 'y1': 2, 'x2': 5, 'y2': 1},
{'x1': 8, 'y1': 6, 'x2': 5, 'y2': 5},
{'x1': 8, 'y1': 10, 'x2': 5, 'y2': 9},
{'x1': 8, 'y1': 4, 'x2': 5, 'y2': 3},
{'x1': 8, 'y1': 8, 'x2': 5, 'y2': 7},
{'x1': 8, 'y1': 2, 'x2': 5, 'y2': 3},
{'x1': 8, 'y1': 6, 'x2': 5, 'y2': 7},
{'x1': 8, 'y1': 10, 'x2': 5, 'y2': 11},
{'x1': 8, 'y1': 1, 'x2': 7, 'y2': 4},
{'x1': 8, 'y1': 5, 'x2': 7, 'y2': 8},
{'x1': 8, 'y1': 9, 'x2': 7, 'y2': 12},
{'x1': 8, 'y1': 7, 'x2': 7, 'y2': 4},
{'x1': 8, 'y1': 5, 'x2': 7, 'y2': 2},
{'x1': 8, 'y1': 9, 'x2': 7, 'y2': 6},
{'x1': 8, 'y1': 3, 'x2': 7, 'y2': 6},
{'x1': 8, 'y1': 7, 'x2': 7, 'y2': 10},
{'x1': 8, 'y1': 4, 'x2': 7, 'y2': 1},
{'x1': 8, 'y1': 8, 'x2': 7, 'y2': 5},
{'x1': 8, 'y1': 2, 'x2': 7, 'y2': 5},
{'x1': 8, 'y1': 6, 'x2': 7, 'y2': 9},
{'x1': 8, 'y1': 10, 'x2': 7, 'y2': 13},
{'x1': 8, 'y1': 4, 'x2': 7, 'y2': 7},
{'x1': 8, 'y1': 8, 'x2': 7, 'y2': 11},
{'x1': 8, 'y1': 6, 'x2': 7, 'y2': 3},
{'x1': 8, 'y1': 10, 'x2': 7, 'y2': 7},
{'x1': 10, 'y1': 5, 'x2': 7, 'y2': 4},
{'x1': 10, 'y1': 9, 'x2': 7, 'y2': 8},
{'x1': 10, 'y1': 3, 'x2': 7, 'y2': 4},
{'x1': 10, 'y1': 7, 'x2': 7, 'y2': 8},
{'x1': 10, 'y1': 1, 'x2': 7, 'y2': 2},
{'x1': 10, 'y1': 5, 'x2': 7, 'y2': 6},
{'x1': 10, 'y1': 9, 'x2': 7, 'y2': 10},
{'x1': 10, 'y1': 3, 'x2': 7, 'y2': 2},
{'x1': 10, 'y1': 7, 'x2': 7, 'y2': 6},
{'x1': 10, 'y1': 4, 'x2': 7, 'y2': 5},
{'x1': 10, 'y1': 8, 'x2': 7, 'y2': 9},
{'x1': 10, 'y1': 2, 'x2': 7, 'y2': 1},
{'x1': 10, 'y1': 6, 'x2': 7, 'y2': 5},
{'x1': 10, 'y1': 10, 'x2': 7, 'y2': 9},
{'x1': 10, 'y1': 4, 'x2': 7, 'y2': 3},
{'x1': 10, 'y1': 8, 'x2': 7, 'y2': 7},
{'x1': 10, 'y1': 2, 'x2': 7, 'y2': 3},
{'x1': 10, 'y1': 6, 'x2': 7, 'y2': 7},
{'x1': 10, 'y1': 10, 'x2': 7, 'y2': 11},
{'x1': 6, 'y1': 5, 'x2': 9, 'y2': 4},
{'x1': 6, 'y1': 9, 'x2': 9, 'y2': 8},
{'x1': 6, 'y1': 3, 'x2': 9, 'y2': 4},
{'x1': 6, 'y1': 7, 'x2': 9, 'y2': 8},
{'x1': 6, 'y1': 1, 'x2': 9, 'y2': 2},
{'x1': 6, 'y1': 5, 'x2': 9, 'y2': 6},
{'x1': 6, 'y1': 9, 'x2': 9, 'y2': 10},
{'x1': 6, 'y1': 3, 'x2': 9, 'y2': 2},
{'x1': 6, 'y1': 7, 'x2': 9, 'y2': 6},
{'x1': 6, 'y1': 4, 'x2': 9, 'y2': 5},
{'x1': 6, 'y1': 8, 'x2': 9, 'y2': 9},
{'x1': 6, 'y1': 2, 'x2': 9, 'y2': 1},
{'x1': 6, 'y1': 6, 'x2': 9, 'y2': 5},
{'x1': 6, 'y1': 10, 'x2': 9, 'y2': 9},
{'x1': 6, 'y1': 4, 'x2': 9, 'y2': 3},
{'x1': 6, 'y1': 8, 'x2': 9, 'y2': 7},
{'x1': 6, 'y1': 2, 'x2': 9, 'y2': 3},
{'x1': 6, 'y1': 6, 'x2': 9, 'y2': 7},
{'x1': 6, 'y1': 10, 'x2': 9, 'y2': 11},
{'x1': 8, 'y1': 1, 'x2': 9, 'y2': 4},
{'x1': 10, 'y1': 1, 'x2': 9, 'y2': 4},
{'x1': 8, 'y1': 5, 'x2': 9, 'y2': 8},
{'x1': 10, 'y1': 5, 'x2': 9, 'y2': 8},
{'x1': 8, 'y1': 9, 'x2': 9, 'y2': 12},
{'x1': 10, 'y1': 9, 'x2': 9, 'y2': 12},
{'x1': 8, 'y1': 7, 'x2': 9, 'y2': 4},
{'x1': 10, 'y1': 7, 'x2': 9, 'y2': 4},
{'x1': 8, 'y1': 5, 'x2': 9, 'y2': 2},
{'x1': 10, 'y1': 5, 'x2': 9, 'y2': 2},
{'x1': 8, 'y1': 9, 'x2': 9, 'y2': 6},
{'x1': 10, 'y1': 9, 'x2': 9, 'y2': 6},
{'x1': 8, 'y1': 3, 'x2': 9, 'y2': 6},
{'x1': 10, 'y1': 3, 'x2': 9, 'y2': 6},
{'x1': 8, 'y1': 7, 'x2': 9, 'y2': 10},
{'x1': 10, 'y1': 7, 'x2': 9, 'y2': 10},
{'x1': 8, 'y1': 4, 'x2': 9, 'y2': 1},
{'x1': 10, 'y1': 4, 'x2': 9, 'y2': 1},
{'x1': 8, 'y1': 8, 'x2': 9, 'y2': 5},
{'x1': 10, 'y1': 8, 'x2': 9, 'y2': 5},
{'x1': 8, 'y1': 2, 'x2': 9, 'y2': 5},
{'x1': 10, 'y1': 2, 'x2': 9, 'y2': 5},
{'x1': 8, 'y1': 6, 'x2': 9, 'y2': 9},
{'x1': 10, 'y1': 6, 'x2': 9, 'y2': 9},
{'x1': 8, 'y1': 10, 'x2': 9, 'y2': 13},
{'x1': 10, 'y1': 10, 'x2': 9, 'y2': 13},
{'x1': 8, 'y1': 4, 'x2': 9, 'y2': 7},
{'x1': 10, 'y1': 4, 'x2': 9, 'y2': 7},
{'x1': 8, 'y1': 8, 'x2': 9, 'y2': 11},
{'x1': 10, 'y1': 8, 'x2': 9, 'y2': 11},
{'x1': 8, 'y1': 6, 'x2': 9, 'y2': 3},
{'x1': 10, 'y1': 6, 'x2': 9, 'y2': 3},
{'x1': 8, 'y1': 10, 'x2': 9, 'y2': 7},
{'x1': 10, 'y1': 10, 'x2': 9, 'y2': 7},
{'x1': 1, 'y1': 5, 'x2': 4, 'y2': 4},
{'x1': 1, 'y1': 9, 'x2': 4, 'y2': 8},
{'x1': 1, 'y1': 3, 'x2': 4, 'y2': 4},
{'x1': 1, 'y1': 7, 'x2': 4, 'y2': 8},
{'x1': 1, 'y1': 1, 'x2': 4, 'y2': 2},
{'x1': 1, 'y1': 5, 'x2': 4, 'y2': 6},
{'x1': 1, 'y1': 9, 'x2': 4, 'y2': 10},
{'x1': 1, 'y1': 3, 'x2': 4, 'y2': 2},
{'x1': 1, 'y1': 7, 'x2': 4, 'y2': 6},
{'x1': 1, 'y1': 4, 'x2': 4, 'y2': 5},
{'x1': 1, 'y1': 8, 'x2': 4, 'y2': 9},
{'x1': 1, 'y1': 2, 'x2': 4, 'y2': 1},
{'x1': 1, 'y1': 6, 'x2': 4, 'y2': 5},
{'x1': 1, 'y1': 10, 'x2': 4, 'y2': 9},
{'x1': 1, 'y1': 4, 'x2': 4, 'y2': 3},
{'x1': 1, 'y1': 8, 'x2': 4, 'y2': 7},
{'x1': 1, 'y1': 2, 'x2': 4, 'y2': 3},
{'x1': 1, 'y1': 6, 'x2': 4, 'y2': 7},
{'x1': 1, 'y1': 10, 'x2': 4, 'y2': 11},
{'x1': 5, 'y1': 1, 'x2': 4, 'y2': 4},
{'x1': 5, 'y1': 5, 'x2': 4, 'y2': 8},
{'x1': 5, 'y1': 9, 'x2': 4, 'y2': 12},
{'x1': 5, 'y1': 7, 'x2': 4, 'y2': 4},
{'x1': 5, 'y1': 5, 'x2': 4, 'y2': 2},
{'x1': 5, 'y1': 9, 'x2': 4, 'y2': 6},
{'x1': 5, 'y1': 3, 'x2': 4, 'y2': 6},
{'x1': 5, 'y1': 7, 'x2': 4, 'y2': 10},
{'x1': 5, 'y1': 4, 'x2': 4, 'y2': 1},
{'x1': 5, 'y1': 8, 'x2': 4, 'y2': 5},
{'x1': 5, 'y1': 2, 'x2': 4, 'y2': 5},
{'x1': 5, 'y1': 6, 'x2': 4, 'y2': 9},
{'x1': 5, 'y1': 10, 'x2': 4, 'y2': 13},
{'x1': 5, 'y1': 4, 'x2': 4, 'y2': 7},
{'x1': 5, 'y1': 8, 'x2': 4, 'y2': 11},
{'x1': 5, 'y1': 6, 'x2': 4, 'y2': 3},
{'x1': 5, 'y1': 10, 'x2': 4, 'y2': 7},
{'x1': 3, 'y1': 1, 'x2': 4, 'y2': 4},
{'x1': 3, 'y1': 5, 'x2': 4, 'y2': 8},
{'x1': 3, 'y1': 9, 'x2': 4, 'y2': 12},
{'x1': 3, 'y1': 7, 'x2': 4, 'y2': 4},
{'x1': 3, 'y1': 5, 'x2': 4, 'y2': 2},
{'x1': 3, 'y1': 9, 'x2': 4, 'y2': 6},
{'x1': 3, 'y1': 3, 'x2': 4, 'y2': 6},
{'x1': 3, 'y1': 7, 'x2': 4, 'y2': 10},
{'x1': 3, 'y1': 4, 'x2': 4, 'y2': 1},
{'x1': 3, 'y1': 8, 'x2': 4, 'y2': 5},
{'x1': 3, 'y1': 2, 'x2': 4, 'y2': 5},
{'x1': 3, 'y1': 6, 'x2': 4, 'y2': 9},
{'x1': 3, 'y1': 10, 'x2': 4, 'y2': 13},
{'x1': 3, 'y1': 4, 'x2': 4, 'y2': 7},
{'x1': 3, 'y1': 8, 'x2': 4, 'y2': 11},
{'x1': 3, 'y1': 6, 'x2': 4, 'y2': 3},
{'x1': 3, 'y1': 10, 'x2': 4, 'y2': 7},
{'x1': 7, 'y1': 5, 'x2': 4, 'y2': 4},
{'x1': 7, 'y1': 9, 'x2': 4, 'y2': 8},
{'x1': 7, 'y1': 3, 'x2': 4, 'y2': 4},
{'x1': 7, 'y1': 7, 'x2': 4, 'y2': 8},
{'x1': 7, 'y1': 1, 'x2': 4, 'y2': 2},
{'x1': 7, 'y1': 5, 'x2': 4, 'y2': 6},
{'x1': 7, 'y1': 9, 'x2': 4, 'y2': 10},
{'x1': 7, 'y1': 3, 'x2': 4, 'y2': 2},
{'x1': 7, 'y1': 7, 'x2': 4, 'y2': 6},
{'x1': 7, 'y1': 4, 'x2': 4, 'y2': 5},
{'x1': 7, 'y1': 8, 'x2': 4, 'y2': 9},
{'x1': 7, 'y1': 2, 'x2': 4, 'y2': 1},
{'x1': 7, 'y1': 6, 'x2': 4, 'y2': 5},
{'x1': 7, 'y1': 10, 'x2': 4, 'y2': 9},
{'x1': 7, 'y1': 4, 'x2': 4, 'y2': 3},
{'x1': 7, 'y1': 8, 'x2': 4, 'y2': 7},
{'x1': 7, 'y1': 2, 'x2': 4, 'y2': 3},
{'x1': 7, 'y1': 6, 'x2': 4, 'y2': 7},
{'x1': 7, 'y1': 10, 'x2': 4, 'y2': 11},
{'x1': 1, 'y1': 1, 'x2': 2, 'y2': 4},
{'x1': 1, 'y1': 5, 'x2': 2, 'y2': 8},
{'x1': 1, 'y1': 9, 'x2': 2, 'y2': 12},
{'x1': 1, 'y1': 7, 'x2': 2, 'y2': 4},
{'x1': 1, 'y1': 5, 'x2': 2, 'y2': 2},
{'x1': 1, 'y1': 9, 'x2': 2, 'y2': 6},
{'x1': 1, 'y1': 3, 'x2': 2, 'y2': 6},
{'x1': 1, 'y1': 7, 'x2': 2, 'y2': 10},
{'x1': 1, 'y1': 4, 'x2': 2, 'y2': 1},
{'x1': 1, 'y1': 8, 'x2': 2, 'y2': 5},
{'x1': 1, 'y1': 2, 'x2': 2, 'y2': 5},
{'x1': 1, 'y1': 6, 'x2': 2, 'y2': 9},
{'x1': 1, 'y1': 10, 'x2': 2, 'y2': 13},
{'x1': 1, 'y1': 4, 'x2': 2, 'y2': 7},
{'x1': 1, 'y1': 8, 'x2': 2, 'y2': 11},
{'x1': 1, 'y1': 6, 'x2': 2, 'y2': 3},
{'x1': 1, 'y1': 10, 'x2': 2, 'y2': 7},
{'x1': 5, 'y1': 5, 'x2': 2, 'y2': 4},
{'x1': 5, 'y1': 9, 'x2': 2, 'y2': 8},
{'x1': 5, 'y1': 3, 'x2': 2, 'y2': 4},
{'x1': 5, 'y1': 7, 'x2': 2, 'y2': 8},
{'x1': 5, 'y1': 1, 'x2': 2, 'y2': 2},
{'x1': 5, 'y1': 5, 'x2': 2, 'y2': 6},
{'x1': 5, 'y1': 9, 'x2': 2, 'y2': 10},
{'x1': 5, 'y1': 3, 'x2': 2, 'y2': 2},
{'x1': 5, 'y1': 7, 'x2': 2, 'y2': 6},
{'x1': 5, 'y1': 4, 'x2': 2, 'y2': 5},
{'x1': 5, 'y1': 8, 'x2': 2, 'y2': 9},
{'x1': 5, 'y1': 2, 'x2': 2, 'y2': 1},
{'x1': 5, 'y1': 6, 'x2': 2, 'y2': 5},
{'x1': 5, 'y1': 10, 'x2': 2, 'y2': 9},
{'x1': 5, 'y1': 4, 'x2': 2, 'y2': 3},
{'x1': 5, 'y1': 8, 'x2': 2, 'y2': 7},
{'x1': 5, 'y1': 2, 'x2': 2, 'y2': 3},
{'x1': 5, 'y1': 6, 'x2': 2, 'y2': 7},
{'x1': 5, 'y1': 10, 'x2': 2, 'y2': 11},
{'x1': 5, 'y1': 1, 'x2': 6, 'y2': 4},
{'x1': 5, 'y1': 5, 'x2': 6, 'y2': 8},
{'x1': 5, 'y1': 9, 'x2': 6, 'y2': 12},
{'x1': 5, 'y1': 7, 'x2': 6, 'y2': 4},
{'x1': 5, 'y1': 5, 'x2': 6, 'y2': 2},
{'x1': 5, 'y1': 9, 'x2': 6, 'y2': 6},
{'x1': 5, 'y1': 3, 'x2': 6, 'y2': 6},
{'x1': 5, 'y1': 7, 'x2': 6, 'y2': 10},
{'x1': 5, 'y1': 4, 'x2': 6, 'y2': 1},
{'x1': 5, 'y1': 8, 'x2': 6, 'y2': 5},
{'x1': 5, 'y1': 2, 'x2': 6, 'y2': 5},
{'x1': 5, 'y1': 6, 'x2': 6, 'y2': 9},
{'x1': 5, 'y1': 10, 'x2': 6, 'y2': 13},
{'x1': 5, 'y1': 4, 'x2': 6, 'y2': 7},
{'x1': 5, 'y1': 8, 'x2': 6, 'y2': 11},
{'x1': 5, 'y1': 6, 'x2': 6, 'y2': 3},
{'x1': 5, 'y1': 10, 'x2': 6, 'y2': 7},
{'x1': 3, 'y1': 1, 'x2': 2, 'y2': 4},
{'x1': 3, 'y1': 5, 'x2': 2, 'y2': 8},
{'x1': 3, 'y1': 9, 'x2': 2, 'y2': 12},
{'x1': 3, 'y1': 7, 'x2': 2, 'y2': 4},
{'x1': 3, 'y1': 5, 'x2': 2, 'y2': 2},
{'x1': 3, 'y1': 9, 'x2': 2, 'y2': 6},
{'x1': 3, 'y1': 3, 'x2': 2, 'y2': 6},
{'x1': 3, 'y1': 7, 'x2': 2, 'y2': 10},
{'x1': 3, 'y1': 4, 'x2': 2, 'y2': 1},
{'x1': 3, 'y1': 8, 'x2': 2, 'y2': 5},
{'x1': 3, 'y1': 2, 'x2': 2, 'y2': 5},
{'x1': 3, 'y1': 6, 'x2': 2, 'y2': 9},
{'x1': 3, 'y1': 10, 'x2': 2, 'y2': 13},
{'x1': 3, 'y1': 4, 'x2': 2, 'y2': 7},
{'x1': 3, 'y1': 8, 'x2': 2, 'y2': 11},
{'x1': 3, 'y1': 6, 'x2': 2, 'y2': 3},
{'x1': 3, 'y1': 10, 'x2': 2, 'y2': 7},
{'x1': 3, 'y1': 5, 'x2': 6, 'y2': 4},
{'x1': 3, 'y1': 9, 'x2': 6, 'y2': 8},
{'x1': 3, 'y1': 3, 'x2': 6, 'y2': 4},
{'x1': 3, 'y1': 7, 'x2': 6, 'y2': 8},
{'x1': 3, 'y1': 1, 'x2': 6, 'y2': 2},
{'x1': 3, 'y1': 5, 'x2': 6, 'y2': 6},
{'x1': 3, 'y1': 9, 'x2': 6, 'y2': 10},
{'x1': 3, 'y1': 3, 'x2': 6, 'y2': 2},
{'x1': 3, 'y1': 7, 'x2': 6, 'y2': 6},
{'x1': 3, 'y1': 4, 'x2': 6, 'y2': 5},
{'x1': 3, 'y1': 8, 'x2': 6, 'y2': 9},
{'x1': 3, 'y1': 2, 'x2': 6, 'y2': 1},
{'x1': 3, 'y1': 6, 'x2': 6, 'y2': 5},
{'x1': 3, 'y1': 10, 'x2': 6, 'y2': 9},
{'x1': 3, 'y1': 4, 'x2': 6, 'y2': 3},
{'x1': 3, 'y1': 8, 'x2': 6, 'y2': 7},
{'x1': 3, 'y1': 2, 'x2': 6, 'y2': 3},
{'x1': 3, 'y1': 6, 'x2': 6, 'y2': 7},
{'x1': 3, 'y1': 10, 'x2': 6, 'y2': 11},
{'x1': 7, 'y1': 1, 'x2': 6, 'y2': 4},
{'x1': 7, 'y1': 5, 'x2': 6, 'y2': 8},
{'x1': 7, 'y1': 9, 'x2': 6, 'y2': 12},
{'x1': 7, 'y1': 7, 'x2': 6, 'y2': 4},
{'x1': 7, 'y1': 5, 'x2': 6, 'y2': 2},
{'x1': 7, 'y1': 9, 'x2': 6, 'y2': 6},
{'x1': 7, 'y1': 3, 'x2': 6, 'y2': 6},
{'x1': 7, 'y1': 7, 'x2': 6, 'y2': 10},
{'x1': 7, 'y1': 4, 'x2': 6, 'y2': 1},
{'x1': 7, 'y1': 8, 'x2': 6, 'y2': 5},
{'x1': 7, 'y1': 2, 'x2': 6, 'y2': 5},
{'x1': 7, 'y1': 6, 'x2': 6, 'y2': 9},
{'x1': 7, 'y1': 10, 'x2': 6, 'y2': 13},
{'x1': 7, 'y1': 4, 'x2': 6, 'y2': 7},
{'x1': 7, 'y1': 8, 'x2': 6, 'y2': 11},
{'x1': 7, 'y1': 6, 'x2': 6, 'y2': 3},
{'x1': 7, 'y1': 10, 'x2': 6, 'y2': 7},
{'x1': 9, 'y1': 5, 'x2': 6, 'y2': 4},
{'x1': 9, 'y1': 9, 'x2': 6, 'y2': 8},
{'x1': 9, 'y1': 3, 'x2': 6, 'y2': 4},
{'x1': 9, 'y1': 7, 'x2': 6, 'y2': 8},
{'x1': 9, 'y1': 1, 'x2': 6, 'y2': 2},
{'x1': 9, 'y1': 5, 'x2': 6, 'y2': 6},
{'x1': 9, 'y1': 9, 'x2': 6, 'y2': 10},
{'x1': 9, 'y1': 3, 'x2': 6, 'y2': 2},
{'x1': 9, 'y1': 7, 'x2': 6, 'y2': 6},
{'x1': 9, 'y1': 4, 'x2': 6, 'y2': 5},
{'x1': 9, 'y1': 8, 'x2': 6, 'y2': 9},
{'x1': 9, 'y1': 2, 'x2': 6, 'y2': 1},
{'x1': 9, 'y1': 6, 'x2': 6, 'y2': 5},
{'x1': 9, 'y1': 10, 'x2': 6, 'y2': 9},
{'x1': 9, 'y1': 4, 'x2': 6, 'y2': 3},
{'x1': 9, 'y1': 8, 'x2': 6, 'y2': 7},
{'x1': 9, 'y1': 2, 'x2': 6, 'y2': 3},
{'x1': 9, 'y1': 6, 'x2': 6, 'y2': 7},
{'x1': 9, 'y1': 10, 'x2': 6, 'y2': 11},
{'x1': 5, 'y1': 5, 'x2': 8, 'y2': 4},
{'x1': 5, 'y1': 9, 'x2': 8, 'y2': 8},
{'x1': 5, 'y1': 3, 'x2': 8, 'y2': 4},
{'x1': 5, 'y1': 7, 'x2': 8, 'y2': 8},
{'x1': 5, 'y1': 1, 'x2': 8, 'y2': 2},
{'x1': 5, 'y1': 5, 'x2': 8, 'y2': 6},
{'x1': 5, 'y1': 9, 'x2': 8, 'y2': 10},
{'x1': 5, 'y1': 3, 'x2': 8, 'y2': 2},
{'x1': 5, 'y1': 7, 'x2': 8, 'y2': 6},
{'x1': 5, 'y1': 4, 'x2': 8, 'y2': 5},
{'x1': 5, 'y1': 8, 'x2': 8, 'y2': 9},
{'x1': 5, 'y1': 2, 'x2': 8, 'y2': 1},
{'x1': 5, 'y1': 6, 'x2': 8, 'y2': 5},
{'x1': 5, 'y1': 10, 'x2': 8, 'y2': 9},
{'x1': 5, 'y1': 4, 'x2': 8, 'y2': 3},
{'x1': 5, 'y1': 8, 'x2': 8, 'y2': 7},
{'x1': 5, 'y1': 2, 'x2': 8, 'y2': 3},
{'x1': 5, 'y1': 6, 'x2': 8, 'y2': 7},
{'x1': 5, 'y1': 10, 'x2': 8, 'y2': 11},
{'x1': 7, 'y1': 1, 'x2': 8, 'y2': 4},
{'x1': 7, 'y1': 5, 'x2': 8, 'y2': 8},
{'x1': 7, 'y1': 9, 'x2': 8, 'y2': 12},
{'x1': 7, 'y1': 7, 'x2': 8, 'y2': 4},
{'x1': 7, 'y1': 5, 'x2': 8, 'y2': 2},
{'x1': 7, 'y1': 9, 'x2': 8, 'y2': 6},
{'x1': 7, 'y1': 3, 'x2': 8, 'y2': 6},
{'x1': 7, 'y1': 7, 'x2': 8, 'y2': 10},
{'x1': 7, 'y1': 4, 'x2': 8, 'y2': 1},
{'x1': 7, 'y1': 8, 'x2': 8, 'y2': 5},
{'x1': 7, 'y1': 2, 'x2': 8, 'y2': 5},
{'x1': 7, 'y1': 6, 'x2': 8, 'y2': 9},
{'x1': 7, 'y1': 10, 'x2': 8, 'y2': 13},
{'x1': 7, 'y1': 4, 'x2': 8, 'y2': 7},
{'x1': 7, 'y1': 8, 'x2': 8, 'y2': 11},
{'x1': 7, 'y1': 6, 'x2': 8, 'y2': 3},
{'x1': 7, 'y1': 10, 'x2': 8, 'y2': 7},
{'x1': 7, 'y1': 5, 'x2': 10, 'y2': 4},
{'x1': 7, 'y1': 9, 'x2': 10, 'y2': 8},
{'x1': 7, 'y1': 3, 'x2': 10, 'y2': 4},
{'x1': 7, 'y1': 7, 'x2': 10, 'y2': 8},
{'x1': 7, 'y1': 1, 'x2': 10, 'y2': 2},
{'x1': 7, 'y1': 5, 'x2': 10, 'y2': 6},
{'x1': 7, 'y1': 9, 'x2': 10, 'y2': 10},
{'x1': 7, 'y1': 3, 'x2': 10, 'y2': 2},
{'x1': 7, 'y1': 7, 'x2': 10, 'y2': 6},
{'x1': 7, 'y1': 4, 'x2': 10, 'y2': 5},
{'x1': 7, 'y1': 8, 'x2': 10, 'y2': 9},
{'x1': 7, 'y1': 2, 'x2': 10, 'y2': 1},
{'x1': 7, 'y1': 6, 'x2': 10, 'y2': 5},
{'x1': 7, 'y1': 10, 'x2': 10, 'y2': 9},
{'x1': 7, 'y1': 4, 'x2': 10, 'y2': 3},
{'x1': 7, 'y1': 8, 'x2': 10, 'y2': 7},
{'x1': 7, 'y1': 2, 'x2': 10, 'y2': 3},
{'x1': 7, 'y1': 6, 'x2': 10, 'y2': 7},
{'x1': 7, 'y1': 10, 'x2': 10, 'y2': 11},
{'x1': 9, 'y1': 1, 'x2': 8, 'y2': 4},
{'x1': 9, 'y1': 1, 'x2': 10, 'y2': 4},
{'x1': 9, 'y1': 5, 'x2': 8, 'y2': 8},
{'x1': 9, 'y1': 5, 'x2': 10, 'y2': 8},
{'x1': 9, 'y1': 9, 'x2': 8, 'y2': 12},
{'x1': 9, 'y1': 9, 'x2': 10, 'y2': 12},
{'x1': 9, 'y1': 7, 'x2': 8, 'y2': 4},
{'x1': 9, 'y1': 7, 'x2': 10, 'y2': 4},
{'x1': 9, 'y1': 5, 'x2': 8, 'y2': 2},
{'x1': 9, 'y1': 5, 'x2': 10, 'y2': 2},
{'x1': 9, 'y1': 9, 'x2': 8, 'y2': 6},
{'x1': 9, 'y1': 9, 'x2': 10, 'y2': 6},
{'x1': 9, 'y1': 3, 'x2': 8, 'y2': 6},
{'x1': 9, 'y1': 3, 'x2': 10, 'y2': 6},
{'x1': 9, 'y1': 7, 'x2': 8, 'y2': 10},
{'x1': 9, 'y1': 7, 'x2': 10, 'y2': 10},
{'x1': 9, 'y1': 4, 'x2': 8, 'y2': 1},
{'x1': 9, 'y1': 4, 'x2': 10, 'y2': 1},
{'x1': 9, 'y1': 8, 'x2': 8, 'y2': 5},
{'x1': 9, 'y1': 8, 'x2': 10, 'y2': 5},
{'x1': 9, 'y1': 2, 'x2': 8, 'y2': 5},
{'x1': 9, 'y1': 2, 'x2': 10, 'y2': 5},
{'x1': 9, 'y1': 6, 'x2': 8, 'y2': 9},
{'x1': 9, 'y1': 6, 'x2': 10, 'y2': 9},
{'x1': 9, 'y1': 10, 'x2': 8, 'y2': 13},
{'x1': 9, 'y1': 10, 'x2': 10, 'y2': 13},
{'x1': 9, 'y1': 4, 'x2': 8, 'y2': 7},
{'x1': 9, 'y1': 4, 'x2': 10, 'y2': 7},
{'x1': 9, 'y1': 8, 'x2': 8, 'y2': 11},
{'x1': 9, 'y1': 8, 'x2': 10, 'y2': 11},
{'x1': 9, 'y1': 6, 'x2': 8, 'y2': 3},
{'x1': 9, 'y1': 6, 'x2': 10, 'y2': 3},
{'x1': 9, 'y1': 10, 'x2': 8, 'y2': 7},
{'x1': 9, 'y1': 10, 'x2': 10, 'y2': 7}]

Access Pandas MultiIndex column by name

I have a spreadsheet imported with pandas like this:
df = pd.read_excel('my_spreadsheet.xlsx',header = [0,1],index_col=0,sheetname='Sheet1')
The output of df.columns is:
MultiIndex(levels=[[u'MR 1', u'MR 10', u'MR 11', u'MR 12', u'MR 13', u'MR 14', u'MR 15', u'MR 16', u'MR 17', u'MR 18', u'MR 19', u'MR 2', u'MR 20', u'MR 21', u'MR 22', u'MR 3', u'MR 4', u'MR 5', u'MR 6', u'MR 7', u'MR 8', u'MR 9'], [u'BIRADS', u'ExamDesc', u'completedDTTM']],
labels=[[0, 0, 0, 11, 11, 11, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 12, 12, 12, 13, 13, 13, 14, 14, 14], [1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0]],
names=[None, u'De-Identified MRN'])
I have been trying to access the values of column named 'De-Identified MRN', but can't seem to find the way to do this.
What I have tried (based on similar posts):
[in] df.index.get_level_values('De-Identified MRN')
[out] KeyError: 'Level De-Identified MRN must be same as name (None)'
and
[in] df.index.unique(level='De-Identified MRN')
[out] KeyError: 'Level De-Identified MRN must be same as name (None)'
UPDATE:
The following did the trick for some reason. I really do not understand the format of the MultiIndex Pandas Dataframe:
pd.Series(df.index)
By using your data
s="MultiIndex(levels=[[u'MR 1', u'MR 10', u'MR 11', u'MR 12', u'MR 13', u'MR 14', u'MR 15', u'MR 16', u'MR 17', u'MR 18', u'MR 19', u'MR 2', u'MR 20', u'MR 21', u'MR 22', u'MR 3', u'MR 4', u'MR 5', u'MR 6', u'MR 7', u'MR 8', u'MR 9'], [u'BIRADS', u'ExamDesc', u'completedDTTM']],labels=[[0, 0, 0, 11, 11, 11, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 12, 12, 12, 13, 13, 13, 14, 14, 14], [1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0]],names=[None, u'De-Identified MRN'])"
idx=eval(s, {}, {'MultiIndex': pd.MultiIndex})
df=pd.DataFrame(index=idx)
df.index.get_level_values(level=1) # df.index.get_level_values('De-Identified MRN')
Out[336]:
Index(['ExamDesc', 'completedDTTM', 'BIRADS', 'ExamDesc', 'completedDTTM',
'BIRADS', 'ExamDesc', 'completedDTTM', 'BIRADS', 'ExamDesc',...
Also if all above still does not work , try
df.reset_index()['De-Identified MRN']
Try the following:
midx = pd.MultiIndex(
levels=[[u'MR 1', u'MR 10', u'MR 11', u'MR 12', u'MR 13', u'MR 14', u'MR 15', u'MR 16', u'MR 17', u'MR 18', u'MR 19', u'MR 2', u'MR 20', u'MR 21', u'MR 22', u'MR 3', u'MR 4', u'MR 5', u'MR 6', u'MR 7', u'MR 8', u'MR 9'], [u'BIRADS', u'ExamDesc', u'completedDTTM']],
labels=[[0, 0, 0, 11, 11, 11, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 12, 12, 12, 13, 13, 13, 14, 14, 14], [1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0]],
names=[None, u'De-Identified MRN']
)
midx.levels[1] # returns the following
Index(['BIRADS', 'ExamDesc', 'completedDTTM'], dtype='object', name='De-Identified MRN')
midx.levels[1].values # returns the following
array(['BIRADS', 'ExamDesc', 'completedDTTM'], dtype=object)

Google Charts is not displaying last row in the data array?

I have data array with 45 rows but only 44 rows are visible on the screen after I am hide columns between 8 and 14 using "setColumns" and then re-enable any of the columns between 8 and 14:
The 45th row has following data:
0:{wf: "10 May 2018, 14:44:36"}
1:{wf: ""}
2:{wf: ""}
3:{wf: ""}
4:{wf: ""}
5:{wf: ""}
6:{wf: ""}
7:{wf: ""}
8:{wf: "69.9"}
9:{wf: "73.2"}
10:{wf: "65.2"}
11:{wf: "73.2"}
12:{wf: "82.8"}
13:{wf: "0"}
14:{wf: "28.6"}
To perform column toggle I use following commands:
performColumnToggle: function (col)
{
// use original unfiltered data
_view = new google.visualization.DataView(_original_data);
// get a key due to splice not keeping keys one delete
var key = $.inArray(col, _toggledColumns);
if (_columns[col]['status'] === 1) {
_columns[col]['status'] = 0;
// delete by key because splice doesn't keep keys on delete
_toggledColumns.splice(key, 1);
} else {
_columns[col]['status'] = 1;
// insert new items with a key and push other columns
_toggledColumns.splice(col, 0, col);
}
// set columns to display
_view.setColumns(_toggledColumns);
console.log(_chart.getDataTable().getNumberOfRows()); // keeps returns 44 rather then 45.
_dashboard.draw(_view);
}
I set _original_data when I first initiate the chart and when I have to update the data in the chart. When I perform console.log(_original_data) I see all 45 rows.
init_chart: function ()
{
_data = new google.visualization.DataTable(_tableData);
_original_data = _data;
// some other code ....
}
updateData: function ()
{
_tableData = data;
_data = new google.visualization.DataTable(_tableData);
_original_data = _data;
// some other code ....
}
Below is an example code
https://jsfiddle.net/Spiker/g0k714h7/
To trigger error take following steps:
Scroll down the page you will notice that we have 45 rows with last row having time date "10 May 2018, 14:44:36"
Scroll back up and click on "Select/Diselect All". You can scroll down the table to see that now we have 44 rows
Either Click on "Select/Diselect All" or "record8". Scroll down the page to see that we still have 44 rows in the table
DataView Class
.hideColumns() Method
DataView Class is a special version of the DataTable Class. Its main purpose is to present a part(s) of the DataTable(s). OP code needs to toggle columns with the method that compliments .setColumns() which is .hideColumns().
In Demo 1 below there is a ternary that toggles the columns from [0,...14] to [8...14] columns by using both set/hideColumns() methods. The table has 90 rows and it persists at 90 between toggling of columns.
Example
var dView = *status === 'on' ?
view.setColumns([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) :
view.hideColumns([0, 1, 2, 3, 4, 5, 6, 7]);
⭐ Demo 2 (located at the bottom of this post,) isn't a solution but it could help the OP code should you decide on not using Demo 1.
Demo 1
.as-console-wrapper.as-console-wrapper {
max-height: 15px;
color: red
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1, user-scalable=no">
<style>
#import url('https://fonts.googleapis.com/css?family=Raleway');
html {
height: 100%;
width: 100%;
font: 400 16px/1.1 Raleway;
}
body {
position: relative;
overflow: auto;
}
main {
overflow: auto;
}
.btn {
width: 11ch;
font: inherit;
}
.btn.on::after {
content: '\a0ON';
}
.btn.off::after {
content: '\a0OFF';
}
.heavy {
font-weight: 900;
}
.darkBkg {
background: rgba(0, 0, 0, 0.4);
color: #fff;
}
.active {
background: rgba(200, 150, 20, 0.3);
color: #000;
}
.tomato {
color: tomato
}
.font {
font-family: Raleway;
}
.right {
text-align: right;
}
.big {
font-size: 20px
}
</style>
</head>
<body>
<main>
<button class='btn off' type='button'>VIEW</button>
<figure id='table'></figure>
</main>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {
'packages': ['table']
});
google.charts.setOnLoadCallback(drawTable);
var cssClassNames = {
'headerRow': 'heavy font',
'tableRow': '',
'oddTableRow': 'darkBkg',
'selectedTableRow': 'active',
'hoverTableRow': 'active',
'headerCell': 'font',
'tableCell': 'right font',
'rowNumberCell': 'big heavy tomato font'
};
var options = {
backgroundColor: {
fill: 'transparent'
},
allowHtml: true,
showRowNumber: true,
width: '100%',
height: '100%',
'cssClassNames': cssClassNames
};
$('.btn').on('click', function(e) {
$(this).toggleClass('on off');
var status = $(this).hasClass('on') ? 'on' : 'off';
console.log(status);
drawTable(status);
});
function drawTable(status) {
var data = new google.visualization.DataTable();
data.addColumn('date', 'START');
data.addColumn('date', 'END');
data.addColumn('string', 'DESC');
data.addColumn('number', '0');
data.addColumn('number', '1');
data.addColumn('number', '2');
data.addColumn('number', '3');
data.addColumn('number', '4');
data.addColumn('number', 'EXT 0');
data.addColumn('number', 'EXT 1');
data.addColumn('number', 'EXT 2');
data.addColumn('number', 'EXT 3');
data.addColumn('number', 'COL 0');
data.addColumn('number', 'COL 1');
data.addColumn('number', 'COL 2');
var time = new google.visualization.DateFormat({
formatType: 'short'
});
data.addRows([
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0],
[new Date(2017, 4, 12), new Date(2019, 4, 12), 'Current', 01, 0.335, 487, 5, 63.20, 52, 23, 105.3, 60, 0.001, 111, -1],
[new Date(1996, 0, 18), new Date(1996, 6, 4), 'Archive', 01, 1.30, 56, 3, 7.08, 88, 23, 98.5, 28, 0.010, 212, 1],
[new Date(2024, 1, 29), new Date(2028, 1, 29), 'Leap', 01, 0.00, 596, 4, 162.2, 971, 23, 92.3, 4, 0.100, 121, 0]
]);
var table = new google.visualization.Table(document.getElementById('table'));
var view = new google.visualization.DataView(data);
var dView = status === 'on' ? view.setColumns([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) : view.hideColumns([0, 1, 2, 3, 4, 5, 6, 7]);
table.draw(view, options);
}
</script>
<!--<script src='gvis-api.js'></script>-->
</body>
</html>
⭐Although I strongly suggest that you use the hideColumns() from Google Visualization API, I'd like to address this:
"// delete by key because splice doesn't keep keys on delete "
splice() returns whatever it deletes. So you call on splice() and store its return in a var, const, array, object, etc.
Demo 2
var columnArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
var removedArray = columnArray.splice(0, 8);
console.log('Removed Column Array: ' + removedArray);
console.log('Remaining Column Array: ' + columnArray);
var restoredArray = removedArray.concat(columnArray);
console.log('Restored Column Array: ' + restoredArray);
the problem appears to occur in function --> switchOffAllColumns
there must be some sort of bug with the view
setting the view columns on the ChartWrapper, rather than the DataView,
corrects the issue
in switchOffAllColumns, change the following line...
_view.setColumns(_toggledColumns);
to...
_chart.setView({
columns: _toggledColumns
});
see following working fiddle...
https://jsfiddle.net/WhiteHat/o0j70y9r/
note: jsapi should no longer be used, changed above fiddle to use loader.js load statement...

CouchDB unable to Reduce Function

Hi all im starting to work with couchdb
im trying to rereduce this reduce function
function(key,values,rereduce){
if(rereduce === true){
//HELP HERE
return results;
}
values.forEach(function(doc){
if(results[(doc.id-1)]){
results[(doc.id-1)].valori.push(doc.valore);
}else{
results[(doc.id-1)] = {
id:doc.id,
nome:doc.nome,
unita:doc.unita,
valori:[doc.valore]
};
}
});
return results;
}
someone can help me to rereduce this?
this is my Map output data
[2015, 7, 6, 0, 0, 26]
ID: bfc53ce117b53ec023c528e0c3039fc7
{nome: "COT ist.INGRESSO ", valore: 309.6, id: 1, unita: "mg/Nm", ora: "00:00:26"}
[2015, 7, 6, 0, 0, 26]
ID: bfc53ce117b53ec023c528e0c303a032
{nome: "COT ist. USCITA ", valore: 5.4, id: 2, unita: "mg/Nm", ora: "00:00:26"}
[2015, 7, 6, 0, 0, 26]
ID: bfc53ce117b53ec023c528e0c303adf4
{nome: "Media TOC NIRA ", valore: 6.8, id: 3, unita: "mg/Nm", ora: "00:00:26"}
[2015, 7, 6, 0, 0, 26]
ID: bfc53ce117b53ec023c528e0c303b6a7
{nome: "Media TOC Giorn. ", valore: 7.3, id: 4, unita: "mg/Nm", ora: "00:00:26"}
[2015, 7, 6, 0, 1, 26]
ID: bfc53ce117b53ec023c528e0c303c3ee
{nome: "COT ist.INGRESSO ", valore: 410.9, id: 1, unita: "mg/Nm", ora: "00:01:26"}
[2015, 7, 6, 0, 1, 26]
ID: bfc53ce117b53ec023c528e0c303c7e6
{nome: "COT ist. USCITA ", valore: 7, id: 2, unita: "mg/Nm", ora: "00:01:26"}
[2015, 7, 6, 0, 1, 26]
ID: bfc53ce117b53ec023c528e0c303cb60
{nome: "Media TOC NIRA ", valore: 6.4, id: 3, unita: "mg/Nm", ora: "00:01:26"}
[2015, 7, 6, 0, 1, 26]
ID: bfc53ce117b53ec023c528e0c303d729
{nome: "Media TOC Giorn. ", valore: 6.9, id: 4, unita: "mg/Nm", ora: "00:01:26"}
[2015, 7, 6, 0, 2, 26]
ID: bfc53ce117b53ec023c528e0c303df8e
{nome: "COT ist.INGRESSO ", valore: 306.7, id: 1, unita: "mg/Nm", ora: "00:02:26"}
etc....
What i need after the reduce is:
[{nome:"COT ist.Ingresso", id:1, unita:"mg/Nm",valori:[309.6,5.4,.....]}
{name:"thename",id:2, unita:"mg/Nm",valori:[6.8,3.5,......]}...]
this is an array of 4 object (one each id) with valori field is the concat of the various valore field, ( ordered by key or ora property)