Google Docs API - Update linked tables - google-docs

I am trying to update tables in Google Documents with the new API. Tables are linked from a Google Sheet.
I tried the API explorer in google cloud. I am able to extract the document in json format and then filter out the tables. But within the table json structure, I do not find anything that I can update, I do not find anything that links the table to a spreadsheet. It is plain text (from the cells in the spreadsheet).
Here I am sharing one table from the json, with 2 rows and 1 column with "Written English" and "Verbal English" as cell value.
"table": {
"rows": 2,
"columns": 1,
"tableRows": [
{
"startIndex": 77,
"endIndex": 95,
"tableCells": [
{
"startIndex": 78,
"endIndex": 95,
"content": [
{
"startIndex": 79,
"endIndex": 95,
"paragraph": {
"elements": [
{
"startIndex": 79,
"endIndex": 94,
"textRun": {
"content": "Written English",
"textStyle": {
"underline": true,
"foregroundColor": {
"color": {
"rgbColor": {
"red": 0.06666667,
"green": 0.33333334,
"blue": 0.8
}
}
},
"fontSize": {
"magnitude": 24,
"unit": "PT"
},
"weightedFontFamily": {
"fontFamily": "Arial",
"weight": 400
}
}
}
},
{
"startIndex": 94,
"endIndex": 95,
"textRun": {
"content": "\n",
"textStyle": {
"foregroundColor": {
"color": {
"rgbColor": {
"red": 0.8784314,
"green": 0.16078432,
"blue": 0.42352942
}
}
},
"fontSize": {
"magnitude": 24,
"unit": "PT"
},
"weightedFontFamily": {
"fontFamily": "Arial",
"weight": 400
}
}
}
}
],
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"lineSpacing": 115,
"direction": "LEFT_TO_RIGHT",
"spacingMode": "COLLAPSE_LISTS",
"spaceAbove": {
"unit": "PT"
},
"avoidWidowAndOrphan": false
}
}
}
],
"tableCellStyle": {
"rowSpan": 1,
"columnSpan": 1,
"backgroundColor": {
"color": {
"rgbColor": {
"red": 1,
"green": 1,
"blue": 1
}
}
},
"borderLeft": {
"color": {
"color": {
"rgbColor": {
"red": 1,
"green": 1,
"blue": 1
}
}
},
"width": {
"magnitude": 0.75,
"unit": "PT"
},
"dashStyle": "SOLID"
},
"borderRight": {
"color": {
"color": {
"rgbColor": {
"red": 1,
"green": 1,
"blue": 1
}
}
},
"width": {
"magnitude": 0.75,
"unit": "PT"
},
"dashStyle": "SOLID"
},
"borderTop": {
"color": {
"color": {
"rgbColor": {
"red": 1,
"green": 1,
"blue": 1
}
}
},
"width": {
"magnitude": 0.75,
"unit": "PT"
},
"dashStyle": "SOLID"
},
"borderBottom": {
"color": {
"color": {
"rgbColor": {
"red": 1,
"green": 1,
"blue": 1
}
}
},
"width": {
"magnitude": 0.75,
"unit": "PT"
},
"dashStyle": "SOLID"
},
"paddingLeft": {
"magnitude": 2,
"unit": "PT"
},
"paddingRight": {
"magnitude": 2,
"unit": "PT"
},
"paddingTop": {
"magnitude": 2,
"unit": "PT"
},
"paddingBottom": {
"magnitude": 2,
"unit": "PT"
},
"contentAlignment": "BOTTOM"
}
}
],
"tableRowStyle": {
"minRowHeight": {
"magnitude": 15,
"unit": "PT"
}
}
},
{
"startIndex": 95,
"endIndex": 112,
"tableCells": [
{
"startIndex": 96,
"endIndex": 112,
"content": [
{
"startIndex": 97,
"endIndex": 112,
"paragraph": {
"elements": [
{
"startIndex": 97,
"endIndex": 111,
"textRun": {
"content": "Verbal English",
"textStyle": {
"underline": true,
"foregroundColor": {
"color": {
"rgbColor": {
"red": 0.06666667,
"green": 0.33333334,
"blue": 0.8
}
}
},
"fontSize": {
"magnitude": 14,
"unit": "PT"
},
"weightedFontFamily": {
"fontFamily": "Raleway",
"weight": 400
}
}
}
},
{
"startIndex": 111,
"endIndex": 112,
"textRun": {
"content": "\n",
"textStyle": {
"foregroundColor": {
"color": {
"rgbColor": {
"red": 0.8784314,
"green": 0.16078432,
"blue": 0.42352942
}
}
},
"fontSize": {
"magnitude": 14,
"unit": "PT"
},
"weightedFontFamily": {
"fontFamily": "Arial",
"weight": 400
}
}
}
}
],
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"lineSpacing": 115,
"direction": "LEFT_TO_RIGHT",
"spacingMode": "COLLAPSE_LISTS",
"spaceAbove": {
"unit": "PT"
},
"avoidWidowAndOrphan": false
}
}
}
],
"tableCellStyle": {
"rowSpan": 1,
"columnSpan": 1,
"backgroundColor": {
},
"borderLeft": {
"color": {
"color": {
"rgbColor": {
"red": 1,
"green": 1,
"blue": 1
}
}
},
"width": {
"magnitude": 0.75,
"unit": "PT"
},
"dashStyle": "SOLID"
},
"borderRight": {
"color": {
"color": {
"rgbColor": {
"red": 1,
"green": 1,
"blue": 1
}
}
},
"width": {
"magnitude": 0.75,
"unit": "PT"
},
"dashStyle": "SOLID"
},
"borderTop": {
"color": {
"color": {
"rgbColor": {
"red": 1,
"green": 1,
"blue": 1
}
}
},
"width": {
"magnitude": 0.75,
"unit": "PT"
},
"dashStyle": "SOLID"
},
"borderBottom": {
"color": {
"color": {
"rgbColor": {
"red": 1,
"green": 1,
"blue": 1
}
}
},
"width": {
"magnitude": 0.75,
"unit": "PT"
},
"dashStyle": "SOLID"
},
"paddingLeft": {
"magnitude": 2,
"unit": "PT"
},
"paddingRight": {
"magnitude": 2,
"unit": "PT"
},
"paddingTop": {
"magnitude": 2,
"unit": "PT"
},
"paddingBottom": {
"magnitude": 2,
"unit": "PT"
},
"contentAlignment": "BOTTOM"
}
}
],
"tableRowStyle": {
"minRowHeight": {
"magnitude": 15,
"unit": "PT"
}
}
}
],
"tableStyle": {
"tableColumnProperties": [
{
"widthType": "FIXED_WIDTH",
"width": {
"magnitude": 363,
"unit": "PT"
}
}
]
}
}
In short, I am trying to programmatically do what "UPDATE" button does on a linked table in Google Docs.
Looking forward to any help.
Thanks.

The issue is created here in the issuetracker. Star(on the top left) the issue to help Google priorotize the issue!

Related

How to use filter on cloud/roleName in Azure Application Insights?

I created the "New Failures Analysis" workbook in Azure Application Insights. In that, I added a custom chart using the below query to display the count of requests, failures, exceptions, etc. based on the cloud/roleName property.
{
"type": 10,
"content": {
"chartId": "xxxxxxxxxxxxxxxxxxx",
"version": "MetricsItem/2.0",
"size": 3,
"chartType": 0,
"resourceType": "microsoft.insights/components",
"metricScope": 0,
"resourceIds": [
"xxxxxxxxxxx"
],
"timeContext": {
"durationMs": 86400000
},
"metrics": [
{
"namespace": "microsoft.insights/components",
"metric": "microsoft.insights/components--requests/count",
"aggregation": 7
},
{
"namespace": "microsoft.insights/components",
"metric": "microsoft.insights/components--requests/failed",
"aggregation": 7
},
{
"namespace": "microsoft.insights/components",
"metric": "microsoft.insights/components--exceptions/count",
"aggregation": 7
},
{
"namespace": "microsoft.insights/components",
"metric": "microsoft.insights/components--requests/duration",
"aggregation": 4
},
{
"namespace": "microsoft.insights/components",
"metric": "microsoft.insights/components--requests/rate",
"aggregation": 4
}
],
"gridFormatType": 2,
"filters": [
{
"key": "cloud/roleName",
"operator": 0,
"values": [
"xxxxxxxxx"
]
}
],
"gridSettings": {
"formatters": [
{
"columnMatch": "Subscription",
"formatter": 5
},
{
"columnMatch": "Name",
"formatter": 5,
"formatOptions": {
"linkTarget": "Resource"
}
},
{
"columnMatch": "Segment",
"formatter": 5
},
{
"columnMatch": "microsoft.insights/components--requests/count",
"formatter": 8,
"formatOptions": {
"min": 0,
"max": 5000,
"palette": "green"
},
"numberFormat": {
"unit": 0,
"options": {
"style": "decimal"
}
}
},
{
"columnMatch": "microsoft.insights/components--requests/count Timeline",
"formatter": 5
},
{
"columnMatch": "microsoft.insights/components--requests/failed",
"formatter": 8,
"formatOptions": {
"min": 0,
"max": 20,
"palette": "orangeRed"
},
"numberFormat": {
"unit": 0,
"options": {
"style": "decimal"
}
}
},
{
"columnMatch": "microsoft.insights/components--requests/failed Timeline",
"formatter": 5
},
{
"columnMatch": "microsoft.insights/components--exceptions/count",
"formatter": 8,
"formatOptions": {
"min": 0,
"max": 20,
"palette": "yellowOrangeRed"
},
"numberFormat": {
"unit": 0,
"options": {
"style": "decimal"
}
}
},
{
"columnMatch": "microsoft.insights/components--exceptions/count Timeline",
"formatter": 5
},
{
"columnMatch": "microsoft.insights/components--requests/duration",
"formatter": 8,
"formatOptions": {
"min": 0,
"max": 1000,
"palette": "yellowGreenBlue"
}
},
{
"columnMatch": "microsoft.insights/components--requests/duration Timeline",
"formatter": 5
},
{
"columnMatch": "microsoft.insights/components--requests/rate",
"formatter": 8,
"formatOptions": {
"min": 0,
"palette": "blueGreen"
},
"numberFormat": {
"unit": 31,
"options": {
"style": "decimal"
}
}
},
{
"columnMatch": "microsoft.insights/components--requests/rate Timeline",
"formatter": 5
}
],
"rowLimit": 10000,
"labelSettings": [
{
"columnId": "microsoft.insights/components--requests/count",
"label": "Requests"
},
{
"columnId": "microsoft.insights/components--requests/count Timeline",
"label": "microsoft.insights/components--requests/count (Count) Timeline"
},
{
"columnId": "microsoft.insights/components--requests/failed",
"label": "Failed"
},
{
"columnId": "microsoft.insights/components--requests/failed Timeline",
"label": "microsoft.insights/components--requests/failed (Count) Timeline"
},
{
"columnId": "microsoft.insights/components--exceptions/count",
"label": "Exceptions"
},
{
"columnId": "microsoft.insights/components--exceptions/count Timeline",
"label": "microsoft.insights/components--exceptions/count (Count) Timeline"
},
{
"columnId": "microsoft.insights/components--requests/duration",
"label": "Avg Response Time"
},
{
"columnId": "microsoft.insights/components--requests/duration Timeline",
"label": "microsoft.insights/components--requests/duration (Average) Timeline"
},
{
"columnId": "microsoft.insights/components--requests/rate",
"label": "Request Rate"
},
{
"columnId": "microsoft.insights/components--requests/rate Timeline",
"label": "microsoft.insights/components--requests/rate (Average) Timeline"
}
]
}
},
"name": "metric - 01"
}
The above query worked fine a few days ago, but suddenly this query is not giving any results, even though the logs are available in the Azure Application Insights for the specific cloud/roleName property.
The metric ID doesn't look quite right. When I add a metric in Workbooks, say, failed requests, I get the ID "metric": "microsoft.insights/components-Failures-requests/failed" instead of "metric": "microsoft.insights/components--requests/failed". I'm curious how this Workbook JSON was generated? I would recreate this metrics step again and check if the issue persists. If it does, also check if you are seeing no results in the Metrics blade as well. If the Workbook continues to show incorrect results afterwards, I would recommend submitting a support request.

Updating dictionary in Python

I'm working on a project where I will retrieve data from various files and this data will then be written down in a file in geojson format.
Below you see a simplified example of some of the code and output:
Code:
def get_data(data):
features = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
data["lat"],
data["long"],
],
},
"properties": {
"obsid": data["file_name"],
"name": data["guid_id"],
"h_gs": data["z"],
},
}
],
}
for id, top, bot, code in zip(
data["id"],
data["top"],
data["bot"],
data["code"],
):
info = {
id: {
"top": top,
"bot": bot,
"code": code,
},
}
features["features"].append(info)
return features
def main(data):
data = get_data(data)
to_json = json.dumps(data, indent=4)
print(to_json)
if __name__ == "__main__":
# example data
data = {
"lat": 40.730610,
"long": -73.935242,
"z": 28.37,
"file_name": "tmrx.txt",
"guid_id": "d4d5b10a-c5fc-450a-9b3b-f309e7cb9613",
"id": ["id_0", "id_1", "id_2", "id_3", "id_4"],
"top": [100, 200, 300, 400, 500],
"bot": [90, 190, 290, 390, 490],
"code": ["a", "b", "c", "d", "e"],
}
main(data)
Output:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
40.73061,
-73.935242
]
},
"properties": {
"obsid": "tmrx.txt",
"name": "d4d5b10a-c5fc-450a-9b3b-f309e7cb9613",
"h_gs": 28.37
}
},
{
"id_0": {
"top": 100,
"bot": 90,
"code": "a"
}
},
{
"id_1": {
"top": 200,
"bot": 190,
"code": "b"
}
},
{
"id_2": {
"top": 300,
"bot": 290,
"code": "c"
}
},
{
"id_3": {
"top": 400,
"bot": 390,
"code": "d"
}
},
{
"id_4": {
"top": 500,
"bot": 490,
"code": "e"
}
}
]
}
This works fine but I wish I could get the output to look a little different.
Desired output:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
40.73061,
-73.935242
]
},
"properties": {
"obsid": "tmrx.txt",
"name": "d4d5b10a-c5fc-450a-9b3b-f309e7cb9613",
"h_gs": 28.37
}
"id_0": {
"top": 100,
"bot": 90,
"code": "a"
}
"id_1": {
"top": 200,
"bot": 190,
"code": "b"
}
"id_2": {
"top": 300,
"bot": 290,
"code": "c"
}
"id_3": {
"top": 400,
"bot": 390,
"code": "d"
}
"id_4": {
"top": 500,
"bot": 490,
"code": "e"
}
}
]
}
There, the 'unnecessary' brackets are removed.
Does anyone here on the forum know how i could achieve this result in the above code?
Best Regards,
Mikael
See the code sample above.
Change below Line in your code
features["features"].append(info)
To this
features["features"][0] |= info
Instead of features["features"].append(info) use:
features["features"][0].update(info)

I am getting duplicate responses in joined contest. I want only single response for every contest

i have worked very hard on this.Please help me out as this is very important. I am not able to find why is it happening.
models.py
class JoinContestlist(models.Model):
user = models.ForeignKey(User,null=True,on_delete=models.CASCADE)
contest_no = models.CharField(max_length=100,null=True, blank=True)
match_id = models.CharField(max_length=100,null=True, blank=True)
spots = models.IntegerField(null=True, blank=True)
entry_fee = models.IntegerField(null=True, blank=True)
price_pool = models.IntegerField(null=True, blank=True)
level = models.JSONField(null=True, blank=True)
no_of_team = models.IntegerField(null=True, blank=True)
remaining_spots = models.IntegerField(null=True, blank=True)
remaining_team = models.IntegerField(null=True, blank=True)
views.py
POST Function
#api_view(['POST'])
def post_join_contest_list(request, id, contest_no, match_id):
try:
if request.method == 'POST':
user = User.objects.get(id=id)
qs = Contest.objects.get(contest_no=contest_no)
cs = MatchList.objects.get(match_id=match_id)
serializer = JoinContestlistserializer(qs, data=request.data)
ks = JoinContestlist.objects.filter(user=user, contest_no=qs.contest_no, match_id=match_id)
if len(ks) < qs.no_of_team:
js = JoinContestlist.objects.create(user=user, spots=qs.spots, entry_fee=qs.entry_fee,
price_pool=qs.price_pool, level=qs.level, no_of_team=qs.no_of_team,
contest_no=qs.contest_no, match_id=cs.match_id)
js.save()
return JsonResponse({"status": True, "message": "success"})
return JsonResponse({"status": False, "message": "Contest is full"})
except:
return JsonResponse({"status": False, "message": "Service temporarily unavailable, try again later"})
GET Function
#api_view(['GET'])
def get_join_contest_list(request, id, match_id):
try:
if request.method == 'GET':
# import pdb
# pdb.set_trace()
user = User.objects.get(id=id)
cs = JoinContestlist.objects.filter(user=user, match_id=match_id)
json_data_2 = []
json_data_4 = []
json_data_1 = []
for k in cs:
qs = JoinContestlist.objects.filter(match_id=k.match_id, contest_no=k.contest_no)
ds = JoinContestlist.objects.filter(user=user, match_id=k.match_id, contest_no=k.contest_no)
a = len(qs)
b = len(ds)
remaining_spots = k.spots - a
remaining_team = k.no_of_team - b
json_data_1.append({
"contest_no": k.contest_no,
"spots": k.spots,
"remaining_spots": remaining_spots,
"entry_fee": k.entry_fee,
"prize_pool": k.price_pool,
"no_of_team": k.no_of_team,
"remaining_team": remaining_team,
"winning": [{"key": q, "value": z} for (q, z) in k.level.items()]
})
return JsonResponse(
{"status": True, "message": "success", "joined_contest": json_data_1, })
except:
return JsonResponse({"status": False, "message": "Service temporarily unavailable, try again later"})
OUTPUT i am getting
{
"status": true,
"message": "success",
"joined_contest": [
{
"contest_no": "13",
"spots": 1118,
"remaining_spots": 1113,
"entry_fee": 99,
"prize_pool": 90759,
"no_of_team": 10,
"remaining_team": 5,
"winning": [
{
"key": "1",
"value": " 5,000 "
},
{
"key": "2",
"value": " 2,000"
},
{
"key": "3-10",
"value": "750"
},
{
"key": "11-100",
"value": "500"
},
{
"key": "101-250",
"value": "140"
},
{
"key": "251-372",
"value": "95"
}
]
},
{
"contest_no": "13",
"spots": 1118,
"remaining_spots": 1113,
"entry_fee": 99,
"prize_pool": 90759,
"no_of_team": 10,
"remaining_team": 5,
"winning": [
{
"key": "1",
"value": " 5,000 "
},
{
"key": "2",
"value": " 2,000"
},
{
"key": "3-10",
"value": "750"
},
{
"key": "11-100",
"value": "500"
},
{
"key": "101-250",
"value": "140"
},
{
"key": "251-372",
"value": "95"
}
]
},
{
"contest_no": "13",
"spots": 1118,
"remaining_spots": 1113,
"entry_fee": 99,
"prize_pool": 90759,
"no_of_team": 10,
"remaining_team": 5,
"winning": [
{
"key": "1",
"value": " 5,000 "
},
{
"key": "2",
"value": " 2,000"
},
{
"key": "3-10",
"value": "750"
},
{
"key": "11-100",
"value": "500"
},
{
"key": "101-250",
"value": "140"
},
{
"key": "251-372",
"value": "95"
}
]
},
{
"contest_no": "13",
"spots": 1118,
"remaining_spots": 1113,
"entry_fee": 99,
"prize_pool": 90759,
"no_of_team": 10,
"remaining_team": 5,
"winning": [
{
"key": "1",
"value": " 5,000 "
},
{
"key": "2",
"value": " 2,000"
},
{
"key": "3-10",
"value": "750"
},
{
"key": "11-100",
"value": "500"
},
{
"key": "101-250",
"value": "140"
},
{
"key": "251-372",
"value": "95"
}
]
},
{
"contest_no": "13",
"spots": 1118,
"remaining_spots": 1113,
"entry_fee": 99,
"prize_pool": 90759,
"no_of_team": 10,
"remaining_team": 5,
"winning": [
{
"key": "1",
"value": " 5,000 "
},
{
"key": "2",
"value": " 2,000"
},
{
"key": "3-10",
"value": "750"
},
{
"key": "11-100",
"value": "500"
},
{
"key": "101-250",
"value": "140"
},
{
"key": "251-372",
"value": "95"
}
]
},
{
"contest_no": "12",
"spots": 50,
"remaining_spots": 45,
"entry_fee": 49,
"prize_pool": 1975,
"no_of_team": 5,
"remaining_team": 0,
"winning": [
{
"key": "1-5",
"value": "125"
},
{
"key": "6-15",
"value": "75"
},
{
"key": "16-30",
"value": "40"
}
]
},
{
"contest_no": "12",
"spots": 50,
"remaining_spots": 45,
"entry_fee": 49,
"prize_pool": 1975,
"no_of_team": 5,
"remaining_team": 0,
"winning": [
{
"key": "1-5",
"value": "125"
},
{
"key": "6-15",
"value": "75"
},
{
"key": "16-30",
"value": "40"
}
]
},
{
"contest_no": "12",
"spots": 50,
"remaining_spots": 45,
"entry_fee": 49,
"prize_pool": 1975,
"no_of_team": 5,
"remaining_team": 0,
"winning": [
{
"key": "1-5",
"value": "125"
},
{
"key": "6-15",
"value": "75"
},
{
"key": "16-30",
"value": "40"
}
]
},
{
"contest_no": "12",
"spots": 50,
"remaining_spots": 45,
"entry_fee": 49,
"prize_pool": 1975,
"no_of_team": 5,
"remaining_team": 0,
"winning": [
{
"key": "1-5",
"value": "125"
},
{
"key": "6-15",
"value": "75"
},
{
"key": "16-30",
"value": "40"
}
]
},
{
"contest_no": "12",
"spots": 50,
"remaining_spots": 45,
"entry_fee": 49,
"prize_pool": 1975,
"no_of_team": 5,
"remaining_team": 0,
"winning": [
{
"key": "1-5",
"value": "125"
},
{
"key": "6-15",
"value": "75"
},
{
"key": "16-30",
"value": "40"
}
]
}
]
}
I am getting duplicate responses in joined contest. I want only single response for every contest.Below is my expected output
EXPECTED OUTPUT
{
"status": true,
"message": "success",
"joined_contest": [
{
"contest_no": "13",
"spots": 1118,
"remaining_spots": 1113,
"entry_fee": 99,
"prize_pool": 90759,
"no_of_team": 10,
"remaining_team": 5,
"winning": [
{
"key": "1",
"value": " 5,000 "
},
{
"key": "2",
"value": " 2,000"
},
{
"key": "3-10",
"value": "750"
},
{
"key": "11-100",
"value": "500"
},
{
"key": "101-250",
"value": "140"
},
{
"key": "251-372",
"value": "95"
}
]
},
{
"contest_no": "12",
"spots": 50,
"remaining_spots": 45,
"entry_fee": 49,
"prize_pool": 1975,
"no_of_team": 5,
"remaining_team": 0,
"winning": [
{
"key": "1-5",
"value": "125"
},
{
"key": "6-15",
"value": "75"
},
{
"key": "16-30",
"value": "40"
}
]
}
]
}
Have you tried distinct() on your query?
https://docs.djangoproject.com/en/4.0/ref/models/querysets/#django.db.models.query.QuerySet.distinct

How to I return a json object along with totals in mongoose?

I have a database of exercises in a workout tracker, and when I do a find(), the result is this:
[
{
"_id": "5e9dacbb6512969974bd5b2d",
"day": "2020-04-10T14:07:55.905Z",
"exercises": [
{
"type": "resistance",
"name": "Bicep Curl",
"duration": 20,
"weight": 100,
"reps": 10,
"sets": 4
}
]
},
{
"_id": "5e9dacbb6512969974bd5b2e",
"day": "2020-04-11T14:07:55.916Z",
"exercises": [
{
"type": "resistance",
"name": "Lateral Pull",
"duration": 20,
"weight": 300,
"reps": 10,
"sets": 4
}
]
},
{
"_id": "5e9dacbb6512969974bd5b2f",
"day": "2020-04-12T14:07:55.916Z",
"exercises": [
{
"type": "resistance",
"name": "Push Press",
"duration": 25,
"weight": 185,
"reps": 8,
"sets": 4
}
]
},
{
"_id": "5e9dacbb6512969974bd5b30",
"day": "2020-04-13T14:07:55.916Z",
"exercises": [
{
"type": "cardio",
"name": "Running",
"duration": 25,
"distance": 4
}
]
},
{
"_id": "5e9dacbb6512969974bd5b31",
"day": "2020-04-14T14:07:55.916Z",
"exercises": [
{
"type": "resistance",
"name": "Bench Press",
"duration": 20,
"weight": 285,
"reps": 10,
"sets": 4
}
]
},
{
"_id": "5e9dacbb6512969974bd5b32",
"day": "2020-04-15T14:07:55.916Z",
"exercises": [
{
"type": "resistance",
"name": "Bench Press",
"duration": 20,
"weight": 300,
"reps": 10,
"sets": 4
}
]
},
{
"_id": "5e9dacbb6512969974bd5b33",
"day": "2020-04-16T14:07:55.916Z",
"exercises": [
{
"type": "resistance",
"name": "Quad Press",
"duration": 30,
"weight": 300,
"reps": 10,
"sets": 4
}
]
},
{
"_id": "5e9dacbb6512969974bd5b34",
"day": "2020-04-17T14:07:55.916Z",
"exercises": [
{
"type": "resistance",
"name": "Bench Press",
"duration": 20,
"weight": 300,
"reps": 10,
"sets": 4
}
]
},
{
"_id": "5e9dacbb6512969974bd5b35",
"day": "2020-04-18T14:07:55.916Z",
"exercises": [
{
"type": "resistance",
"name": "Military Press",
"duration": 20,
"weight": 300,
"reps": 10,
"sets": 4
}
]
},
{
"_id": "5e9dacbb6512969974bd5b36",
"day": "2020-04-19T14:07:55.916Z",
"exercises": [
{
"type": "resistance",
"name": "Bench",
"duration": 30,
"distance": 2
}
]
}
]
Then I need to get total sums of statistics from each exercise, so I used mongoose aggregate to give me this data:
[
{
"_id": null,
"totalDuration": 230,
"totalWeight": 2070,
"totalSets": 32,
"totalReps": 78,
"totalDistance": 6
}
]
I want to combine these two results in one GET request, ideally doing something similar to a push where I just push the totals at the end of the first JSON object. How do I achieve this?
Something like this:
function mergeResults(resultFromFindQuery, totalSums){
var allData = {};
allData['mongoFindresult'] = resultFromFindQuery;
allData['totalSums'] = totalSums;
return allData;
}
Then use the returned value to what you need to do. Now you have both of them in the same variable.

Crosshair-x won't display on line chart

I am having an issue with a line chart on my site. Everything works fine about it except no matter what I try, I cannot get the crosshair-x value/scale to show up. http://gyazo.com/42a34d0fed9c2912bf7ed40eb0c55144 Both are set to "visible": true. My JSON code is as follows:
var myChart = {
"type": "line",
"background-color": "transparent",
"utc": true,
"title": {
"y": "0px",
"text": '#myClasses.STARTDATETIME.ToString("MM/d/yyyy (h:mm tt)")',
"background-color": "transparent",
"font-size": "16px",
"font-color": "#666",
"font-weight": "bold",
"letter-spacing": "0.1225em",
"height": "25px"
},
"plotarea": {
"margin":"10% 8% 14% 12%",
"background-color":"#666"
},
"legend": {
"visible": false,
},
"scale-x": {
"min-value": myEpoch,
"shadow": 0,
"step": #ViewBag.TotalTime,
"line-color": "#fff",
"tick": {
"line-color": "#f6f7f8"
},
"guide": {
"line-color": "#f6f7f8",
"visible": true
},
"item": {
"font-color": "#666"
},
"transform": {
"type": "date",
"all": "%D,%d %M<br />%h:%i %A",
"item": {
"visible": false
}
},
"label": {
"visible": false,
"font-color": "#666"
},
"minor-ticks": 0
},
"scale-y": {
"values": "25:200:25",
"line-color": "#fff",
"shadow": 0,
"tick": {
"line-color": "#f6f7f8"
},
"guide": {
"visible": false
},
"item": {
"font-color": "#666"
},
"label": {
"text": "Heart Rate (BPM)",
"font-color": "#666"
},
"minor-ticks": 0,
"thousands-separator": ",",
"markers": [
{
"type": "area",
"range": [25, 60],
"backgroundColor": "#585857",
"alpha": 1
},
{
"type": "area",
"range": [60, 95],
"backgroundColor": "#6FCBDC",
"alpha": 1
},
{
"type": "area",
"range": [95, 130],
"backgroundColor": "#8BC540",
"alpha": 1
},
{
"type": "area",
"range": [130, 165],
"backgroundColor": "#F38220",
"alpha": 1
},
{
"type": "area",
"range": [165, 200],
"backgroundColor": "#EB2026",
"alpha": 1
}
]
},
"tooltip": {
"font-color": "#666",
"visible": false
},
"chart": {
"marginRight": 30,
"marginLeft": 70
},
"plot": {
"tooltip-text": "%t bpm: %v",
"shadow": 0,
"line-width": "3px",
"marker": {
"type": "circle",
"size": 2
},
"hover-marker": {
"type": "circle",
"size": 4,
"border-width": "1px"
}
},
"series": [
{
"values": [88,96,93,88,88,86,89,120,144,153,156,132,113,145,138,152,135,155,164,165,147,143,152,140,153,138,116,125,131,132,134,124,111,136,167,171,165,168,139,129,138,130,140,141],
"text": "",
"line-color": "#ffffff",
"marker": {
"background-color": "#ffffff",
"border-width": 1,
"shadow": 0,
"border-color": "#ffffff",
"visible": true
},
"palette": 0
}
],
"crosshair-x": {
"line-color": "#f6f7f8",
"value-label": {
"border-radius": "5px",
"border-width": "1px",
"border-color": "#f6f7f8",
"padding": "0px 10px 0px 5px",
"font-weight": "bold",
"font-color": "#fff",
"background-color": "#666",
"visible": true
},
"scale-label": {
"font-color": "#fff",
"background-color": "#666",
"border-radius": "5px",
"border-width": "1px",
"border-color": "#f6f7f8",
"padding": "0px 10px 0px 5px",
"visible": true
}
}
};
Is there anything obvious that I'm missing that may be overruling those being set to visible?
Thanks in advance for your help!
Which version of ZingChart are you using? Does this occur in all browsers? Are you getting any console errors? I've taken your code and put it into our demo tool, and the crosshair seems to work. Take a look here.
You can try adding the following to the <head> element of your application:
<style title="zingchart"></style>
This forces ZingChart to inject its CSS into that element, preventing certain types of conflicts that can occur from time to time, but I'm not 100% sure that this is the issue.
I'm on the ZingChart support team, so I'd love to help, but I can't reproduce the issue on my end.

Resources