I'm trying to insert a scatter plot inside a tab as in the code below however nothing seems to work. I have tried a number of combinations with dash HTML elements, inserting children= etc and I gave up. Could someone explain what I am actually doing wrong, please?
def create_scatterpage():
app.layout = html.Div([([
dcc.Tabs([
dcc.Tab(
px.scatter(
surfacing,
x="Barcode",
y="Machine",
size="Barcode",
color="Category",
hover_name="timeSince",
log_x=False,
log_y=False,
size_max=70,
labels={
"TimeSince": "Average time since last update(min)",
"Machine": "Machine code",
"Category": "Department",
"Barcode": "Number of jobs",
}, title="Surfacing Orders Movement Tracking")
),
dcc.Tab(
px.scatter(
coating,
x="Barcode",
y="Machine",
size="Barcode",
color="Category",
hover_name="timeSince",
log_x=False,
log_y=False,
size_max=70,
labels={
"TimeSince": "Average time since last update(min)",
"Machine": "Machine code",
"Category": "Department",
"Barcode": "Number of jobs",
}, title="Coating Orders Movement Tracking"))])])])
return app.layout
current error:
An object was provided as children instead of a component, string,
or number (or list of those).
Related
So in my angular project, I want to render an array of product object.
I was able to render it as JSON object:
<td>{{o.products |json}}</td>
And for example this one of the outputs:
[ { "id": 4, "name": "Forever", "description": "Because you suffer a lot physically and morally, we will not let you suffer financially.\n• Lump sum payment: Up to US $500,000 paid immediately upon diagnosis of any covered 32 critical illnesses.\n• Worldwide coverage: Giving you the assistance you need even if you move to another country.\n• Telemedicine and e-counsultancy through World Care International: Access to free expert care from world-renowned medical centres in the US specialising in your condition.", "price": 300, "logo": "assets\\download(5).jpg", "category": 1, "image": "assets\\forever.jpg" } ]
Now what if I only want to show the name attribute and not the whole product attributes. How can I do that?
You should use ngFor directive, to create a for-loop that iterates over all products, and print only the product name:
<td *ngFor="let product of o.products">{{product.name}}</td>
I'm trying to set up a heatmap graph for request latencies in grafana, using a stackdriver backend.
With the following query I get the right heatmap, however the bucket labels are in seconds without decimals, which means there is an 8,4,2 and 1 second bucket, and then many 0 second buckets. Is there a way to switch to ms labels?
For clarification: the bucket names coming back in the result of the query are integers, so changing the units or decimal places in the visualisation won't help.
Query as seen in grafana editor (for better readability)
Currently the graph looks like this
"queries": [
{
"refId": "A",
"intervalMs": 15000,
"datasourceId": 14,
"metricType": "serviceruntime.googleapis.com/api/request_latencies",
"crossSeriesReducer": "REDUCE_SUM",
"perSeriesAligner": "ALIGN_DELTA",
"alignmentPeriod": "stackdriver-auto",
"groupBys": [],
"view": "FULL",
"filters": [
// -> some more removed for privacy reasons
"AND",
"resource.type",
"=",
"api"
],
"aliasBy": "{{bucket}}",
"type": "timeSeriesQuery"
}
]
I am doing some analytics on a certain website, and I'm trying to get people's search terms to an easier format. They're in JSON format, and I've already parsed the column several times to get other relevant data. The problem is that when trying to parse the keywords/search data, each search word goes into its own column, and with tens of thousands of searches it becomes a problem. Hard to explain, so I will add a picture that illustrates the problem.
The "Ai O" and "JAHAHASHAS" are searches that I did on the website, rest are hidden, but the list goes on forever
https://i.imgur.com/5IXTXn1.png
Here is an example of a person searching "business model" in the JSON
"{""sort"": ""lastUpdated"", ""limit"": 5, ""fields"": {""keywords"": {""business model"": true}}, ""offset"": 0}"
Tried to parse the keywords column anyways, but creating thousands of new columns doesn't really work
I added some extra records to your json file, I hope that it matches what you have to work with in reality. In the future, you'll get faster and better results if you're willing to share a bit more concrete information about your project. In most cases, it's very difficult to provide meaningful advice if we can't reasonably recreate your situation.
Anyway, I wanted the solution to work against multiple search terms, so I tweaked the JSON you provided to look like this:
{ "Searches": [
{"sort": "lastUpdated", "limit": 5, "fields": {"keywords": {"business model": true}}, "offset": 0},
{"sort": "lastUpdated", "limit": 5, "fields": {"keywords": {"Alpha Beta": true}}, "offset": 0},
{"sort": "lastUpdated", "limit": 5, "fields": {"keywords": {"Gamma Delta Epsilon": true}}, "offset": 0}
]}
and then provided the following Power Query (taken from the advanced editor)
let
Source = Json.Document(File.Contents("C:\Users\XXXXXX\Desktop\foo.json")),
#"Converted to Table" = Table.FromList(Source[Searches], Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"fields"}, {"Fields"}),
#"Expanded Fields" = Table.ExpandRecordColumn(#"Expanded Column1", "Fields", {"keywords"}, {"keywords"}),
#"Added Custom" = Table.AddColumn(#"Expanded Fields", "keywords_text", each Record.FieldNames([keywords])),
#"Extracted Values" = Table.TransformColumns(#"Added Custom", {"keywords_text", each Text.Combine(List.Transform(_, Text.From), " "), type text}),
#"Added Custom1" = Table.AddColumn(#"Extracted Values", "keywords_text_list", each Text.Split([keywords_text], " ")),
Custom1 = List.Combine( #"Added Custom1"[keywords_text_list])
in
Custom1
After loading the data from file, I extracted the records (searches, that is) from the Json.
Next, having converted the data to a table, I expanded twice to dive down from Records to Fields, and Fields to keywords. Then I added a custom column and used the M Query 'Record.Fieldnames' function to generate a list on every fieldnames in our keyword collections. Keep in mind, each list here only has one element, even though there might be spaces in that text.
Then I extracted values from those lists
and followed that up by splitting those strings back into lists -- this time using space as a delimiter.
As a final step, I combined the multiple lists into a single list of all our keywords as single elements.
So, that's my approach. Hope it helps.
I have a column of data called Date and I am using that to perform a switch. Basically the figure needs to be 120 on a weekday and 0 on a weekend so I have used.
=SWITCH
(Weekday(Fields!Date.Value) = "1", "0",
Weekday(Fields!Date.Value) = "2", "120",
Weekday(Fields!Date.Value) = "3", "120",
Weekday(Fields!Date.Value) = "4", "120",
Weekday(Fields!Date.Value) = "5", "120",
Weekday(Fields!Date.Value) = "6", "120",
Weekday(Fields!Date.Value) = "7", "0"
)
Which works great. However I also want a Total at the bottom of the sheet. I (somewhat naively) tried adding
=SUM( ... )
to the expression but that resulted in an #Error in the textbox. I also tried
=SUM(ReportItems!Textbox85.value)
and that didn't even run throwing the error
The Value expression for the textrun
'Textbox84.Paragraphs[0].TextRuns[0]' uses an aggregate function on a
report item. Aggregate functions can be used only on report items
contained in page headers and footers.
So my question is how do I sum up this switch function or do I need to rethink this? I guess functionally all I really need is count of the total weekdays so far "this" month (that stays accurate no matter what month is picked using the date parameters). I can then * that number by 120.
So I came at it from a different angle and tried a SQL based solution. I added a column with the code
,CASE
WHEN
DATEPART(dw,convert(date,format(dateadd(hh,1,[Start Time]),'dd/MM/yyyy'),103)) in (1,7)
THEN 0
ELSE 1
End as [weekday]
Then used
=Fields!weekday.Value*120
in my textbox and
=Sum(Fields!weekday.Value, "DataSet1")*120
in my total. Got the desired results.
I'm trying to track daily stats for an individual.
I'm having a hard time adding a new day inside "history" and can also use a pointer on updating "walkingSteps" as new data comes in.
My schema looks like:
{
"_id": {
"$oid": "50db246ce4b0fe4923f08e48"
},
"history": [
{
"_id": {
"$oid": "50db2316e4b0fe4923f08e12"
},
"date": {
"$date": "2012-12-24T15:26:15.321Z"
},
"walkingSteps": 10,
"goalStatus": 1
},
{
"_id": {
"$oid": "50db2316e4b0fe4923f08e13"
},
"date": {
"$date": "2012-12-25T15:26:15.321Z"
},
"walkingSteps": 5,
"goalStatus": 0
},
{
"_id": {
"$oid": "50db2316e4b0fe4923f08e14"
},
"date": {
"$date": "2012-12-26T15:26:15.321Z"
},
"walkingSteps": 8,
"goalStatus": 0
}
]
}
db.history.update( ? )
I've been browsing (and attempting) the mongodb documentation but they don't quite break it all the way down to dummies like myself... I couldn't quite translate their examples to my setup.
Thanks for any help.
E = noob trying to learn programming
Adding a day:
user = {_id: ObjectId("50db246ce4b0fe4923f08e48")}
day = {_id: ObjectId(), date: ISODate("2013-01-07"), walkingSteps:0, goalStatus: 0}
db.users.update(user, {$addToSet: {history:day}})
Updating walkingSteps:
user = ObjectId("50db246ce4b0fe4923f08e48")
day = ObjectId("50db2316e4b0fe4923f08e13") // second day in your example
query = {_id: user, 'history._id': day}
db.users.update(query, {$set: {"history.$.walkingSteps": 6}})
This uses the $ positional operator.
It might be easier to have a separate history collection though.
[Edit] On the separate collections:
Adding days grows the document in size and it might need to be relocated on the disk. This can lead to performance issues and fragmentation.
Deleting days won't shrink the document size on disk.
It makes querying easier/straightforward (e.g. searching for a period of time)
Even though #Justin Case puts the right answer he doesn't explain a few things in it extremely well.
You will notice first of all that he gets rid of the resolution on dates and moves their format to merely the date instead of date and time like so:
day = {_id: ObjectId(), date: ISODate("2013-01-07"), walkingSteps:0, goalStatus: 0}
This means that all your dates will have 00:00:00 for their time instead of the exact time you are using atm. This increases the ease of querying per day so you can do something like:
db.col.update(
{"_id": ObjectId("50db246ce4b0fe4923f08e48"),
"history.date": ISODate("2013-01-07")},
{$inc: {"history.$.walkingSteps":0}}
)
and other similar queries.
This also makes $addToSet actually enforce its rules, however since the data in this sub document could change, i.e. walkingSteps will increment $addToSet will not work well here anyway.
This is something I would change from the ticked answer. I would probably use $push or something else instead since $addToSet is heavier and won't really do anything useful here.
The reason for a separate history collection in my view would be what you said earlier with:
Yes, the amount of history items for that day.
So this array contains a set of days, which is fine but it sounds like the figure that you wish to get walkingSteps from, a set of history items, should be in another collection and you set walkingSteps according to the count of the amount of items in that other collection for today:
db.history_items.find({date: ISODate("2013-01-07")}).count();
Referring to MongoDB Manual, $ is the positional operator which identifies an element in an array field to update without explicitly specifying the position of the element in the array. The positional $ operator, when used with the update() method and acts as a placeholder for the first match of the update query selector.
So, if you issue a command to update your collection like this:
db.history.update(
{someCriterion: someValue },
{ $push: { "history":
{"_id": {
"$oid": "50db2316e4b0fe4923f08e12"
},
"date": {
"$date": "2012-12-24T15:26:15.321Z"
},
"walkingSteps": 10,
"goalStatus": 1
}
}
)
Mongodb might try to identify $oid and $date as some positional parameters. $ also is part of the atomic operators like $set and $push. So, it is better to avoid use this special character in Mongodb.