I am using GRPCv3 on node.js
I have a .proto file with the following message:
message ProductAvailabilityWithRatesResponse {
// How many slots are available for this day/time. Mandatory.
int32 capacity = 1;
// Date for when this product is available. Mandatory.
Date date = 2;
// When does this event start? Unset if this product does not support times.
Time time = 3;
// When does a pickup for this product start? Unset if this product does not support times or pickups.
Time pickupTime = 4;
// Rates with prices. Mandatory (should at least have one entry).
repeated RateWithPrice rates = 5;
}
on the server using console.log i see this output:
{ capacity: 1,
date: { year: 2019, month: 7, day: 1 },
rates: [ { rateId: 1, pricePerPerson: [Object] } ],
time: { hour: 9, minute: 0 } }
and on a client using node.js too:
{ rates:
[ { rateId: '1',
pricePerPerson: [Object],
pricingOptions: 'pricePerPerson' } ],
capacity: 0,
date: { year: 2019, month: 7, day: 1 },
time: { hour: 9, minute: 0 },
pickupTime: null }
but another person using a java client tells me that he sees:
2019-06-26 10:59:39,442 ← getProductAvailability::grpc response {date { year: 2019 month: 7 day: 1 } time { hour: 9 } rates { rateId: "1" pricePerPerson { pricingCategoryWithPrice { pricingCategoryId: "30" price { currency: "EUR" amount: "145" } } pricingCategoryWithPrice { pricingCategoryId: "31" price { currency: "EUR" amount: "150" } } } }}
where capacity is not set.
If it's value is 1 and not 0, everything works well everywhere.
Is it possible?
How can i force the server to output the value?
I already tried using capacity = parseInt(capacity)
Related
Technology: NodeJS.
Problem: "how do I prepare the meeting date every odd or even days for the specified period in this way"
Thanks in advance, it would help me a lot if you could give me an example or direction on this.
let create = {
start_date: "01-02-2023",
end_date: "01-06-2023",
start_time: "15:00",
end_time: "19:00",
days: "even",
};
let meetings = [
{
date: "01-01-2023",
start__time: "14:00",
end__time: "16:00",
},
{
date: "03-01-2023",
start__time: "14:00",
end__time: "16:00",
},
{
date: "05-01-2023",
start__time: "14:00",
end__time: "16:00",
},
];
I tried some node packages but I couldn't produce the desired result.
I'm trying to add a string (Week) next to the week number in xAxes in Chartjs 3. But it shows a random number instead of the string.
Here is the part of my code in the options:
scales: {
x: {
type: 'time',
time: {
unit: 'week',
displayFormats: {
week: "'Week' W",
},
tooltipFormat: 'YYYY-W',
},
ticks: {
source: 'data',
},
offset: true,
},
.........
Current output:
'51124' 10
Expected output:
Week 10
any help would be appreciated.
Thanks
"'Week' W" is a formating string, depending on which adapter you are using 'Week' will be translated to a specific value.
You could check if your adapter support custom strings in the format-string,...
Or you try to modify the label with a callback, like shown here in the documentation: https://www.chartjs.org/docs/latest/axes/labelling.html
Here the relevat code, adapted to fit your code snippet:
...
scales: {
x: {
type: 'time',
time: {
unit: 'week',
displayFormats: {
week: 'W',
}
},
ticks: {
// This prepends the "Week" before the label
callback: function(value, index, ticks) {
return '"Week" ' + value;
}
}
}
}
...
Currently I am making scheduling system and storing information in mongodb
partial of my model looks like this
{
timings: [{from: "00:00", to: "01:00"}],
weekend: [0, 5, 6]
}
I am not sure if this will be good in the long run
can you please help me decide how to better store time in my documents
MongoDB does not have any time/interval data type, so you have to build your own solution. Some general notes:
Use week days according to ISO-8601 standard, i.e. first day (1) of week is Monday. Then it will be easier to create a Date value with $dateFromParts. For hour values use always 24-hour format.
You may consider to store times as
{from: {hour: 0, minute: 0}, to: {hour: 13, minute: 0}}
Otherwise, when you have to create Date value (e.g. for comparison), then it would be:
{
$dateFromParts : {
...,
hour: { $toInt: { $arrayElemAt: [ { $split: [ "$from", ":" ] }, 0 ] } },
minute: { $toInt: { $arrayElemAt: [ { $split: [ "$from", ":" ] }, 1 ] } }
}
}
Compared to
{
$dateFromParts : {
...,
hour: "$from.hour",
minute: "$from.minute"
}
}
Another approach is to store real Date, e.g. 0000-01-01T13:00:00 or any other arbitrary day value. When you use such values, simply ignore the date part.
Or you store number of minutes (0..1'440) or seconds (0..86'400) from midnight. However, such numbers are not user-friendly to read.
i have a mongoose document that contains two ages. The minimum age to go to the attraction and the maximum one.
I need to query my database to get all attractions between 0 and 2 years old.
But this won't work :
"ageMin": {
"$lte": 2
},
"ageMax": {
"$gte": 0
},
Because most of my attraction are between 0 and 99.
To help you visualise i made an example:
attractionOne: {
name: "Deadly Looping",
ageMin: 12,
ageMax: 99
}
attractionTwo: {
name: "Easy Ladybug",
ageMin: 0,
ageMax: 12
}
Thank you.
If you need to match if those ranges are overlapping with 0-2 range then you're close, just need to check if 0-2 range is between min and max age. Try:
db.attractions.find({ ageMin: { $lte: 0 }, ageMax: { $gte: 2 } })
I have ~100 documents coming in per hour. Every document has a viewers property (integer).
By the end of the day I want to aggregate an array of 24 documents, one for every hour of the day, represented by the document with the highest viewers count.
My query so far:
// query, fetch all documents of a specific day
var query = {
bool : {
filter : [
{
range : {
'created' : {
gte : day,
lte : day + (60 * 60 * 24)
}
}
}
]
}
}
// aggregation
var aggs = {
// ?
}
I think this could be achieved using Date Histogram plus Top Hits aggregations. Look at this:
{
"size": 0,
"aggs": {
"articles_over_time": {
"date_histogram": {
"field": "created",
"interval": "minute"
},
"aggs": {
"Viewers": {
"top_hits": {
"size": 1,
"sort": [
{
"viewers": {
"order": "desc"
}
}
]
}
}
}
}
}
}
Date Histogram aggregation will create buckets for each hour in filtered date range and top hits agg will bring back document with highest viewers (we're ordering documents by viewers in descending order and bringing top 1 hit).
Let me know if this works.