Add multiple business hours for 1 day and show business hours in Month View - vue.js

I am using fullcalendar.io.
businessHours: [
{
daysOfWeek: [ 1, 2, 3],
startTime: '10:00',
endTime: '12:00',
},
{
daysOfWeek: [ 1, 2, 3],
startTime: '15:00',
endTime: '18:00',
}
]
I have one custom setting for a store on my website where they are only open between 10 Am to 12 PM and from 3 pm to 6 pm, I am using the full calendar to show their timing but here when I apply this setting its not working.
How can I show grey background during other timing which is not in business hours (i.e in between 12 PM to 3 PM)?

Related

Retrieving full object on click chartJS

Im new to Chart.js and im trying make a line chart where it is possible to click somewhere in the line graph and retrieve the full data object.
This is what my chart looks like right now which is working fine but now I would like to use this my own data
const myLineChart = new Chart(ctx, {
type: 'line',
data: {
labels: ['9:00', '12:00', '15:00', '9:00', '12:00', '15:00', '9:00', '12:00', '15:00', '9:00', '12:00', '15:00',],
datasets: [{
label: 'Cardscans',
data: [
214,
200,
195,
214,
200,
320,
214,
200,
299,
214,
200,
210],
fill: false,
borderColor: 'rgb(75, 192, 192)',
tension: 0.2,
pointStyle: 'circle',
pointRadius: 5,
pointHoverRadius: 15
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}});
So now I want to fill the line chart with the total scans and the pie chart with 'successful' and 'failed'.
I would like to use for example this array of objects:
[
{
id: 1,
date: '01-10-2022',
Scans: {
total: 206151,
times: [
{
time: '12:00 - 13:00',
successful: 12283,
failed: 24,
0: 12184,
1: 55,
2: 22,
3: 12,
4: 8,
5: 2,
}
]
}
},
{
....
}]
What I want to achieve is to fill a pie chart with the 'successful' and 'Failed' data. But I want to do this based on the previous clicked data in the Line chart.
So my question is not about how to click something in the line chart but more about how i fill my line chart with the data above and pull the specific object to fill the other pie chart with.
Thanks in advance

Find all nearest date from list of date in kotlin

I have current date and I have of list which is coming from server. I want to find all first nearest data.
"Results": [
{
"date": "May 9, 2020 8:09:03 PM",
"id": 1
},
{
"date": "Apr 14, 2020 8:09:03 PM",
"id": 2
},
{
"date": "Mar 15, 2020 8:09:03 PM",
"id": 3
},
{
"date": "May 9, 2020 8:19:03 PM",
"id": 4
}
],
Today date is Wed Jul 20 00:00:00 GMT+01:00 2022 I am getting through this my own StackOverflow. Inside this SO I am taking current date.
Expected Output
[Result(date=May 9, 2020 8:09:03 PM, id = 1), Result(date=May 9, 2020 8:19:03 PM, id = 4)]
So How can I do in idiomatic way in kotlin ?
There are quite a few ways this question could be solved with, ranging from simple to moderately complex depending on requirements such as efficiency. With some assumptions, below is a linear-time solution that is decently idiomatic and is only 3 lines in essence.
import kotlin.math.abs
import java.lang.Long.MAX_VALUE
import java.time.LocalDateTime
import java.time.temporal.ChronoUnit
import java.time.temporal.Temporal
data class Result(val date: LocalDateTime, val id: Int)
fun getClosestDays(toDate: Temporal, results: List<Result>): List<Result> {
// Find the minimum amount of days to the current date
var minimumDayCount = MAX_VALUE
results.forEach { minimumDayCount = minOf(minimumDayCount, abs(ChronoUnit.DAYS.between(toDate, it.date))) }
// Grab all results that match the minimum day count
return results.filter { abs(ChronoUnit.DAYS.between(toDate, it.date)) == minimumDayCount }
}
fun main() {
getClosestDays(
LocalDateTime.now(),
listOf(
Result(LocalDateTime.of(2020, 5, 9, 8, 9, 3), 1),
Result(LocalDateTime.of(2020, 4, 14, 8, 9, 3), 2),
Result(LocalDateTime.of(2020, 3, 15, 8, 9, 3), 3),
Result(LocalDateTime.of(2020, 5, 9, 8, 19, 3), 4)
)
).also { println(it) }
}
Here is the output:
[Result(date=2020-05-09T08:09:03, id=1), Result(date=2020-05-09T08:19:03, id=4)]
And here you can play with it yourself.

Api gives wrong data

I use the Google AdWords API to collect information about the search volume for a specific keyword. But the data I get as a response doesn't match with the data from the keyword planner or other keyword tools. Here I check the search volume for the keyword "Hunde" in Berlin, Germany in german.
targeting_service = adwordsClient.GetService('TargetingIdeaService')
selector = {'ideaType': 'KEYWORD', 'requestType' : 'STATS'}
selector['requestedAttributeTypes'] = ['KEYWORD_TEXT', 'SEARCH_VOLUME', 'TARGETED_MONTHLY_SEARCHES']
offset = 0
selector['paging'] = {'startIndex' : str(offset), 'numberResults' : str(1)}
selector['searchParameters'] = [{
'xsi_type': 'RelatedToQuerySearchParameter',
'queries': ["hunde"]
}]
selector['searchParameters'].append({
'xsi_type': 'LocationSearchParameter',
'locations': [{'id': '1003854'}]
})
selector['searchParameters'].append({
'xsi_type': 'LanguageSearchParameter',
'languages': [{'id': '1001'}]
})
page = targeting_service.get(selector)
print(page)
As a response I get:
{
'totalNumEntries': 1,
'entries': [
{
'data': [
{
'key': 'KEYWORD_TEXT',
'value': {
'Attribute.Type': 'StringAttribute',
'value': 'hunde'
}
},
{
'key': 'TARGETED_MONTHLY_SEARCHES',
'value': {
'Attribute.Type': 'MonthlySearchVolumeAttribute',
'value': [
{
'year': 2020,
'month': 12,
'count': 4743382
},
{
'year': 2020,
'month': 11,
'count': 455583
},
{
'year': 2020,
'month': 10,
'count': 8797951
},
{
'year': 2020,
'month': 9,
'count': 5218694
},
{
'year': 2020,
'month': 8,
'count': 5089585
},
{
'year': 2020,
'month': 7,
'count': 3149591
},
{
'year': 2020,
'month': 6,
'count': 3020638
},
{
'year': 2020,
'month': 5,
'count': 4928527
},
{
'year': 2020,
'month': 4,
'count': 754959
},
{
'year': 2020,
'month': 3,
'count': 5649676
},
{
'year': 2020,
'month': 2,
'count': 1590789
},
{
'year': 2020,
'month': 1,
'count': 2506674
}
]
}
},
{
'key': 'SEARCH_VOLUME',
'value': {
'Attribute.Type': 'LongAttribute',
'value': 3825504
}
}
]
}
]
}
But this data doesn't match with the data from the keyword planer.
Avg. monthly searches (Keyword planner): 10K – 100K
Does somebody knows why the data I'm receiving is wrong?
These questions pop up somewhat frequently and are generally not easy to answer. Did you make sure that the specified searchParameters in your request correspond exactly to what you are using in the Keyword Planner?
Additionally, you could check out the KeywordPlanService of the newer Ads API. According to this post by a Google Ads API advisor, it should be closer to what you can do in the web UI than the Adwords API's TargetingIdeaService.
If OP didn't figure it out, i've had the same headaches.
I solved this when adding NetworkSearchParameter to [searchparameter] so the API only returns google data.
my code after adding in the additional argument.
selector['searchParameters'] = [{
'xsi_type' : 'RelatedToQuerySearchParameter',
'queries' : sublist,
},
{
'xsi_type':'LocationSearchParameter',
'locations' : [country_ids[country]],
},
{
'xsi_type': 'NetworkSearchParameter',
'networkSetting': {
'targetGoogleSearch': True,
'targetSearchNetwork': False,
'targetContentNetwork': False,
'targetPartnerSearchNetwork': False
}}]

How to get an average value in a timescale in Postgres?

I have a lot of values in a postgres db that include a time value.
The database contains a record unit colors, something like this:
[
{
id: 1234,
unit: 2,
color: "red",
time: "Wed, 16 Dec 2020 21:45:30"
},
{
id: 1235,
unit: 2,
color: "red",
time: "Wed, 16 Dec 2020 21:47:30"
},{
id: 1236,
unit: 6,
color: "blue",
time: "Wed, 16 Dec 2020 21:48:30"
},
{
id: 1237,
unit: 6,
color: "green",
time: "Wed, 16 Dec 2020 21:49:30"
},
{
id: 1237,
unit: 6,
color: "blue",
time: "Wed, 16 Dec 2020 21:49:37"
},
]
I want to be able to query this list but in 10 minute averages, which should return the earliest record which contains the average.
For example in the 10 minute period of 21:40 - 21:50 I should only recieve the 2 unique units with the average value that they had within that time period.
The returned data should look something like this:
[
{
id: 1234,
unit: 2,
color: "red",
time: "Wed, 16 Dec 2020 21:45:30"
},
{
id: 1236,
unit: 6,
color: "blue",
time: "Wed, 16 Dec 2020 21:48:30"
},
]
What type of query should I be using to acheive soething like this?
Thanks
You can use distinct on:
select distinct on (x.time_trunc, t.unit) t.*
from mytable t
cross join lateral (values (
date_trunc('hour', time)
+ extract(minute from time) / 10 * '10 minute'::interval)
) as x(time_trunc)
order by x.time_trunc, t.unit, t.time
The trick is to truncate the timestamps to 10 minute. For this, we use date arithmetics; I moved the computation in a lateral join so there is no need to repeat the expression. Then, distinct on comes into play, to select the earlier record per timestamp bucket and per unit.
I don't see how the question relates to an average whatsoever.

How to use own data key in victory native instead of x and y which is by default used to draw the chart

How to use own data key in victory native instead of x and y which is by default used to draw the chart
As seen in the below code i want to use myx instead of x to represent data at x-axis and step as y in y-axis.
Instead of this....
sampleData=[
{ key:'1',x: 'Jan', y: 5.5, c0: 2,date:'18 Jan 2019',bank:'Bank Of India',txid:'76jhdg74rh4h848r58'},
{ key:'2',x: 'Feb', y: 3, c0: 1.5, date:'08 Feb 2019',bank:'Bank Of Baroda',txid:'76jhdg74rh4h848r58'},
{ key:'3',x: 'March', y: 5, c0: 2 ,date:'19 March 2019',bank:'State Bank of India',txid:'76jhdg74rh4h848r58'},
{ key:'4',x: 'Apr', y: 4, c0: 1 ,date:'18 Apr 2019',bank:'Bank Of India',txid:'76jhdg74rh4h848r58'},
{ key:'5',x: 'May', y: 6, c0: 2 ,date:'15 May 2019',bank:'Bank Of India',txid:'76jhdg74rh4h848r58'},
{ key:'6',x: 'June', y: 2, c0: 4 ,date:'11 June 2019',bank:'Canara Bank',txid:'76jhdg74rh4h848r58'},
{ key:'7',x: 'July', y: 3, c0: 1 ,date:'28 July 2019',bank:'Punjab National Bank',txid:'76jhdg74rh4h848r58'},
]
I want this data is used to the chart....
sampleData=[
{ key:'1',myx: 'Jan', step: 5.5, c0: 2,date:'18 Jan 2019',bank:'Bank Of India',txid:'76jhdg74rh4h848r58'},
{ key:'2',myx: 'Feb',step: 3, c0: 1.5, date:'08 Feb 2019',bank:'Bank Of Baroda',txid:'76jhdg74rh4h848r58'},
{ key:'3',myx: 'March', step: 5, c0: 2 ,date:'19 March 2019',bank:'State Bank of India',txid:'76jhdg74rh4h848r58'},
{ key:'4',myx: 'Apr', step: 4, c0: 1 ,date:'18 Apr 2019',bank:'Bank Of India',txid:'76jhdg74rh4h848r58'},
{ key:'5',myxx: 'May', step: 6, c0: 2 ,date:'15 May 2019',bank:'Bank Of India',txid:'76jhdg74rh4h848r58'},
{ key:'6',myx: 'June', step: 2, c0: 4 ,date:'11 June 2019',bank:'Canara Bank',txid:'76jhdg74rh4h848r58'},
{ key:'7',myx: 'July', step: 3, c0: 1 ,date:'28 July 2019',bank:'Punjab National Bank',txid:'76jhdg74rh4h848r58'},
]
In this I want to use myx as a x-axis data and step as a y- axis data to draw the chart
You could do it like so:
<VictoryLine
data={ sampleData }
y={"step"}
x={"myx"}
/>
You can define your x and y axis by adding those properties