I'm trying to get a venue's business hours via the foursquare API. Can't seem to find it in the docs.
Is there a way to do it? The official app has access to it.
Call the venues/VENUE_ID endpoint for a venue with hours and then look for an "hours" stanza in the response. It'll look like this:
hours: {
status: "Open today until 1:00 AM",
isOpen: true,
timeframes: [
{
days: "Mon,Tue,Wed,Sun",
open: [
{
renderedTime: "11:00 AM–Midnight"
}
],
segments: [ ]
},
{
days: "Thu–Sat",
includesToday: true,
open: [
{
renderedTime: "11:00 AM–1:00 AM"
}
],
segments: [ ]
}
]
},
Related
[
{
day: 'Mon',
time : [
{
start_time: '10:00',
end_time: '13:00'
},
{
start_time: '16:00',
end_time: '24:00'
}
]
}
]
like this code with using nodejs
I am currently developing a cash register app. I am using a model-controller-view-repository design. I have a cart model that holds products, and when a sale is validated, it clones the cart and adds a date.
My question is: how can I get all the sales done in a specific period of time in a given year.
Example of what I want: «http://localhost:PORT/sales/month/3» would get all sales done in march, « http://localhost:PORT/sales/month/3/week/1 » would get all sales done in the first week of march etc...
I tried several things but I am still lost in MEAN stack. Thanks, I hope my post is not too confusing
EDIT: with some more understanding, I managed to list what I wanted, but I currently no idea how to implement it using my design. Here is the code:
db.ventes.aggregate(
{$project : {
month : {$month : "$dateVente"},
year :{$year : "$dateVente"},
_id : 1
}},
{$match : {month : 1 ,year : 2021 }
}
)
I managed to find a solution.
This is my repository:
exports.findByMonth = async payload => {
return await Vente.aggregate([
{$project : {
date: "$dateVente",
month : {$month : "$dateVente"},
year : {$year : "$dateVente"},
subTotal: 1,
_id : 1
}},
{$match : {month : payload.month ,year : payload.year }}
]
)
}
This is my Controller:
exports.getVenteByMonth = async (req, res) => {
try {
let targetDate = {
month: req.body.month,
year: req.body.year
}
let ventesByMonth = await venteRepository.findByMonth(targetDate)
res.status(200).json({
status: true,
data: ventesByMonth
})
} catch (err) {
res.status(500).json({
status: false,
error: err
})
}
}
This is the result:
{
"status": true,
"data": [
{
"_id": "600ab585a16ea2072ce0e0f5",
"subTotal": 196,
"date": "2021-01-22T11:22:40.876Z",
"month": 1,
"year": 2021
},
{
"_id": "600c391b5b0612027d9f75c2",
"subTotal": 115,
"date": "2021-01-23T14:46:14.846Z",
"month": 1,
"year": 2021
},
{
"_id": "600c3bdf2cca74037320520f",
"subTotal": 0,
"date": "2021-01-23T15:08:10.683Z",
"month": 1,
"year": 2021
},
{
"_id": "600c3fd76acde803e589c7ff",
"subTotal": 147,
"date": "2021-01-23T15:25:02.032Z",
"month": 1,
"year": 2021
}
]
}
And this is my route:
router.get("/monthly", venteController.getVenteByMonth);
I would appreciate if anyone had time to comment on how I organized my files, and if it makes any sense at all, or if there is any "cleaner" way to do so, thanks !
This is my first question here as I have been stuck at a point where I am not able to query my database which has stored dates in "DD/MM/YYYY" String format by using moment
_id:5eb3ebfe2faf4a001719b5b1
post:"some random post"
date:"07/05/2020"
time:"11:07:42 AM"
username:"random user"
__v:0
I want to display all post done by the user in a current month or last month for query for a single date I can do
date.find({"date":"07/05/2020"},function(err,result){
})
but if I want to query the whole month like */05/2020 how to do it ?
If you have saved the date in the string format you can match it directly with regex
collection.find({ date: { $regex: "\/05\/2020"}} ,function(err,result){ })
Working link for above code - https://mongoplayground.net/p/ZE-IneeXb6A
Or If you will use aggregation you can separate the day, month and year and then match whatever you want.
db.collection.aggregate(
[
{
$project:
{
day: { $substr: [ "$date", 0, 2 ] },
month: { $substr: [ "$date", 3, 2 ] },
year: { $substr: [ "$date", 6, 4 ] }
}
},
{ $match : { "month" : "05", "year":"2020"} }
]
)
Working link for above code - https://mongoplayground.net/p/MiG5HUzXI7r
the shortest query I can think of...
db.collection.find({
"date": {
$regex: "[0-9]{2}\/05\/2020"
}
})
I am using Analytics Reporting v4 and Node.js.
I need to get a number of triggered events for a group of dimensions.
For example:
dimensions: date, source, medium, campaign
metrics: pageviews, totalEvents
where eventAction = "Test Action"
When I combine these two metrics: pageviews and totalEvents,
it shows the wrong numbers in result. But when I use them separately, then it works well.
True results for metrics:
total pageviews - 32 (but shows 17)
total events - 9
Maybe someone knows why? Maybe because it does not calculate pageviews where the user didn't do an action ("Test Action")? And how can I do this correctly?
Response example - http://i.imgur.com/BUkqiQG.png
Request code:
reportRequests: [{
view_id: viewId,
dateRanges: [{
startDate: '2020-02-10',
endDate: '2020-02-10',
}],
dimensions: [
{
name: 'ga:date'
},
{
name: 'ga:source'
},
{
name: 'ga:medium'
},
{
name: 'ga:campaign'
}
],
metrics: [
{
expression: 'ga:pageviews'
},
{
expression: 'ga:totalEvents'
},
],
orderBys: [{
fieldName: 'ga:date',
sortOrder: "ASCENDING"
}],
dimensionFilterClauses: [{
filters: [
{
dimension_name: 'ga:eventAction',
operator: 'EXACT',
expressions: ["Test Action"]
}
]
}]
}]
This is because you are filtering down the pages to those which only have the event.
The source, medium, campaign dimensions are all session level. Therefore, when you report on those, and just pageviews, they give total pageviews.
However, when you filter the results to where eventAction=Test, it only returns the pageviews where that event action occurred.
Instead of this, I would suggest using a segment, something like:
"segments": [{
"dynamicSegment": {
"sessionSegment": {
"segmentFilters": [{
"simpleSegment" :{
"orFiltersForSegment": [{
"segmentFilterClauses":[{
"dimensionFilter": {
"dimensionName": "ga:eventAction",
"expressions": ["Test Action"]
}
}]
}]
}
}]
}
}
}]
More info: https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet#DynamicSegment
I have a collection of documents with 2 fields in string format like the below example
{"starts_at": "2019-12-01T18:51:56", "ends_at": "2019-12-05T18:51:56"}
{"starts_at": "2019-12-03T04:38:24", "ends_at": "2019-12-16T04:38:24"}
I want to update the "ends_at" field to be updated by 1 extra day if the difference between the "start_at" and "end_at" is greater than 7. The expected output is like second document "ends_at" get changed.
{"starts_at": "2019-12-01T18:51:56", "ends_at": "2019-12-05T18:51:56"}
{"starts_at": "2019-12-03T04:38:24", "ends_at": "2019-12-17T04:38:24"}
I tried the below approach
First I created a new field with date difference using command
db.myCollection.aggregate([{$addFields: {
DateDiff:{$trunc:{
$divide:[{
$subtract:[{$dateFromString:{dateString:"$ends_at"}},{$dateFromString:{ dateString: "$starts_at"}}]},
1000*60*60*24]}}
}}])
When I tried to update the collection I am not able to find the newly created field. For updating I use
db.myCollection.update({DateDiff:{ $gte:7}},
{$set:{"ends_at":{$add:[{$dateFromString:{dateString:"$ends_at"}},1*24*60*60*1000]}}})
How should I update the "ends_at" field as "String" data type itself by adding extra 1 day in single MongoDB command.
I want to update the "ends_at" field to be updated by 1 extra day if
the difference between the "start_at" and "end_at" is greater than 7.
The expected output is like second document "ends_at" get changed.
The following aggregate query will do the update. The date operators $dateFromString and $dateToString are used to convert the string date to a date field, do the comparison / arithmetic, and then convert back to string. Note the query works with MongoDB version 4.2.
db.test.updateMany(
{ },
[
{ $set: { ends_at: {
$cond: [ { $gt: [
{ $subtract: [
{ $dateFromString: { dateString: "$ends_at" } },
{ $dateFromString: { dateString: "$starts_at" } }
]
},
{ $multiply: [ 7, 86400000 ] }
]
},
{ $dateToString: {
date: { $add: [ { $dateFromString: { dateString: "$ends_at" } }, 86400000 ] },
format: "%Y-%m-%dT%H:%M:%S"
} },
"$ends_at"
]
} } },
]
)