I am trying to schedule 7 different notification on a daily basis with the following code.
const interval = 1440;
for (let i = 0; i < 7; i++) {
const notification = new firebase.notifications.Notification()
.setNotificationId(notifyId + i.toString())
.setTitle('Quote of the Day')
.setBody('today is a beautiful day')
.setData({
dailyQuote:'today is a beautiful day'
});
const date = new Date();
date.setMinutes(date.getMinutes() + (i * interval));
const schedule = {
fireDate: date.getTime(),
repeatInterval: 'day',
};
firebase.notifications().scheduleNotification(notification, schedule);
}
However, the notifications fire all at once at the same time even though fireDate is set exactly 1440 minutes (1 day) later.
Can anyone help? Thanks!
Changing the repeatInterval to 'week' did the trick for me.
const schedule = {
fireDate: date.getTime(),
repeatInterval: 'week',
};
Related
I'm currently using a TimeTickStrategy on the xAxis to show data flowing in real time. However, it's formatting the data using the unix epoch as {hours:minutes:seconds}.
Below is my xAxis code:
xAxis1 = chart.getDefaultAxisX()
.setTickStrategy(AxisTickStrategies.Time, (tickStrategy) => tickStrategy.setTimeOrigin(this.originTime))
.setScrollStrategy(AxisScrollStrategies.progressive)
.setMouseInteractions(false)
.setInterval(60000 * -15, 60000) //xAxis Range(Min,Max) = (origin - 15 minutes, origin + 1 minute)
I'd like to have that formatted in the local time, but I didn't see any options for that when I was reading through the TimeTickStrategy documentation:
https://www.arction.com/lightningchart-js-api-documentation/v3.4.0/classes/timetickstrategy.html
Example (MST):
457050:14:51 --> 11:14:51 AM
Is there a way to do this?
Seems like TimeTickStrategy has no configuration options for formatting.
Maybe you can use DateTimeTickStrategy? It's a bit clumsy but it has quite extensive configuration methods. Here's some kind of an example I whipped up.
/*
* LightningChartJS example showcasing the TimeTickStrategy feature with scrolling data and axis.
*/
// Extract required parts from LightningChartJS.
const {
lightningChart,
AxisScrollStrategies,
AxisTickStrategies,
Themes,
emptyTick,
} = lcjs
// Import data-generators from 'xydata'-library.
const {
createProgressiveTraceGenerator
} = xydata
const chart = lightningChart().ChartXY({
theme: Themes.darkGold,
})
.setTitle('Scrolling TimeTickStrategy example')
.setPadding({ right: 40 })
const axisX = chart
.getDefaultAxisX()
// Enable TimeTickStrategy for X Axis.
.setTickStrategy(AxisTickStrategies.DateTime, ticks => ticks
.setGreatTickStyle(emptyTick)
.setFormattingSecond(
undefined,
{ hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: true },
(x) => 'minor'
)
)
// Configure progressive ScrollStrategy.
.setScrollStrategy(AxisScrollStrategies.progressive)
// Set view to 15 seconds
.setInterval(-1 * 15 * 1000, 0)
.setAnimationScroll(false)
const axisY = chart.getDefaultAxisY()
.setAnimationScroll(false)
// Add 3 series for real-time signal monitoring.
const seriesList = new Array(3).fill(0).map((_, iSeries) =>
chart
.addLineSeries({
dataPattern: {
pattern: 'ProgressiveX',
},
})
)
const legend = chart.addLegendBox().add(chart)
// Dispose example UI elements automatically if they take too much space. This is to avoid bad UI on mobile / etc. devices.
.setAutoDispose({
type: 'max-width',
maxWidth: 0.30,
})
// Stream live timestamp data into series.
// Application displays timestamps as offset from when application started (starts at 00:00:00).
const timeOrigin = Date.now()
Promise.all(
seriesList.map((_) =>
createProgressiveTraceGenerator()
.setNumberOfPoints(60 * 1000)
.generate()
.toPromise(),
),
).then((data) => {
let dataAmount = 0
const pushData = () => {
const nDataPoints = 1
seriesList.forEach((series, iSeries) => {
const seriesData = data[iSeries]
const seriesPoints = []
for (let i = 0; i < nDataPoints; i += 1) {
seriesPoints.push({
// TimeTickStrategy interprets values as milliseconds (UNIX timestamp).
// Exactly same as JavaScript Date APIs.
x: Date.now() - timeOrigin,
y: seriesData[(dataAmount + i) % seriesData.length].y,
})
}
series.add(seriesPoints)
})
dataAmount += nDataPoints
requestAnimationFrame(pushData)
}
pushData()
})
<script src="https://unpkg.com/#arction/lcjs#3.4.0/dist/lcjs.iife.js"></script>
<script src="https://unpkg.com/#arction/xydata#1.2.1/dist/xydata.iife.js"></script>
I have been trying to use the riot games api to compute all the previous custom games and then find the win loss streaks for individual players, I have built the following code to grab matches for a particular user.
See https://github.com/FriendlyUser/deno-riot-games-custom-games
But I feel like the riot games api is only returning data with its v4 api up to season 11, if anyone could clarify how the api works or explain how I could possibly get more data, that would be fantastic.
import { writeJson } from "https://deno.land/std/fs/mod.ts"
import "https://deno.land/x/dotenv/load.ts"
const player_id = Deno.env.get('ACCOUNT_ID')
const region_url = 'https://na1.api.riotgames.com'
let riot_URL = new URL(`${region_url}/lol/match/v4/matchlists/by-account/${player_id}`)
enum HTTP {
GET = 'GET',
POST = 'POST',
PUT = 'PUT',
DELETE = 'DELETE'
}
interface MatchlistDto {
startIndex: number
totalGames: number
endIndex: number
matches: Array<any>
}
function makeFetchOptions(
riotKey = Deno.env.get('RIOT_API_KEY'),
method: HTTP = HTTP.GET
): object {
return {
method: method,
headers: {
"Accept-Charset": "application/x-www-form-urlencoded; charset=UTF-8",
"Accept-Language": "en-US,en;q=0.9",
'X-Riot-Token': riotKey
}
}
}
function appendMatchHistory(riot_endpoint: string): Promise<MatchlistDto> {
const riotKey = Deno.env.get('RIOT_API_KEY')
console.log(riotKey)
const options = makeFetchOptions(riotKey)
return fetch(riot_endpoint, options)
.then( (resp: any) => {
console.log(resp)
return resp.json()
})
.then( (matchData: MatchlistDto) => {
return matchData
})
}
const max_iterations = 1000
let bIndex = 0
let eIndex = 100
let current_url = riot_URL
let riot_endpoint = null
let allMatches = []
let customGames = []
const sleep = (milliseconds: number) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
for (let i = 0; i < max_iterations; i++) {
console.log(`beginIndex: ${bIndex} endIndex: ${eIndex}`)
riot_endpoint = current_url.toString()
const newMatches = await appendMatchHistory(riot_endpoint)
await sleep(1500)
current_url.searchParams.delete('beginIndex')
current_url.searchParams.delete('endIndex')
const {matches} = newMatches
if (matches.length == 0) {
console.log(`ENDING SCRIPT AT ${eIndex} with ${matches.length}`)
break
}
// startIndex becomes endIndex
bIndex = eIndex
eIndex = eIndex + 100
allMatches.push(newMatches.matches)
// get new url
current_url.searchParams.append('beginIndex', String(bIndex))
current_url.searchParams.append('endIndex', String(eIndex))
}
await writeJson(
"./allData.json",
allMatches
);
Sorry if this answer is late. But yes the Riot API is only for "current" data, and that is why sites like U.GG, OP.GG, etc actually run scripts to store data continuously. So to get statistics you would have to write scripts to store it into your own DB over time.
Sadly, there is no way to get previous season data
I have a difficulty here showing video using react-native-video.
The server is using Express, and using GridFSBucket to retrieve the video from mongodb.
The problem is that:
The video from GridFSBucket won't show. But when I tried to place the video in public folder, it will show.
So, my guess is that there is something wrong with how I serve the video. Here is my code from the server:
const bucket = new GridFSBucket(db.original(), { bucketName: "fs" });
const fileDetail = await db.original().collection("fs.files").findOne({_id: idObj});
if (isNullOrUndefined(fileDetail)) {
throw new NoContentException(`asset not found for id ${id}`);
}
const range = req.headers["range"]
if (range && typeof range === "string") {
const parts = range.replace(/bytes=/, "").split("-");
const partialstart = parts[0];
const partialend = parts[1];
const start = parseInt(partialstart, 10);
const end = partialend ? parseInt(partialend, 10) : fileDetail.length - 1;
const chunksize = (end - start) + 1;
res.writeHead(206, {
'Accept-Ranges': 'bytes',
'Content-Length': chunksize,
'Content-Range': 'bytes ' + start + '-' + end + '/' + fileDetail.length,
'Content-Type': fileDetail.contentType
});
bucket.openDownloadStream(idObj, {start, end}).pipe(res);
} else {
res.header('Content-Length', fileDetail.length);
res.header('Content-Type', fileDetail.contentType);
bucket.openDownloadStream(idObj).pipe(res);
}
Thanks in advance for your answer ^_^
I found the solution.
The line:
bucket.openDownloadStream(idObj, {start, end}).pipe(res);
should be:
bucket.openDownloadStream(idObj, {start, end: end - 1}).pipe(res);
Long time browser, first time questioner.
So for an in and out board I need employees to click the "out button" and with a Vue.js v-on:click() next to it I want to to display "Out at 3:55pm".
Here is the button -
<button class="btn btn-smaller btn-out" v-show="user.in" v-on:click="updateOut(user)">out</button>
Which in turn updates the usersRef timeOut status in the Firebase DB like this -
updateOut: function (user) {usersRef.child(user['.key']).child('in').set(false)
usersRef.child(user['.key']).child('timeOut').set(Date())
},
Which updates this with the actual date stamp -
{{ user.timeOut }}
The problem I am getting is that I can not format this inside the updateOut function to simply show "out at 3:55pm". I can only get it to show "Wed Mar 29 2017 10:55:02 GMT-0600 (MDT)"
Srinivas - I can't get this to work. I tried this -
methods: {
addUser: function () {
if (this.newUserName) {
usersRef.push({
name: this.newUserName,
in: false,
returnTime: ''
})
this.newUserName = ''
},
},
getTime: function(user) {
const outTime = new Date(this.user.timeOut)
const hours = outTime.getHours()
let minutes = outTime.getMinutes()
if (minutes < 10) minutes = "0" + minutes // prepend 0
return (hours + ":" + minutes)
},
updateReturnTime: function (user, newText) {
usersRef.child(user['.key']).child('returnTime').set(newText)
},
updateIn: function (user) {
usersRef.child(user['.key']).child('in').set(true)
usersRef.child(user['.key']).child('timeOut').set('')
},
updateOut: function (user) {
usersRef.child(user['.key']).child('in').set(false)
usersRef.child(user['.key']).child('timeOut').set(Date.now())
},
You can create a method to convert date into required format.
methods: {
getTime() {
const outTime = new Date(this.user.timeOut)
const hours = outTime.getHours()
let minutes = outTime.getMinutes()
if (minutes < 10) minutes = "0" + minutes // prepend 0
return (hours + ":" + minutes)
}
}
If you are using this method in multiple places, you can create a filter.
Vue.filter('getTime', function(date) {
const outTime = new Date(date)
const hours = outTime.getHours()
let minutes = outTime.getMinutes()
if (minutes < 10) minutes = "0" + minutes // prepend 0
return (hours + ":" + minutes)
})
You can use it template like this.
{{ user.timeOut | getTime }}
I was wondering how to make a simple countdown timer that would countdown on the server, but show how long was left on the client.
Server:
timeToClear.remove({}); //Removes the previous time calls
Meteor.setInterval(function(){ //The Actual Countdown
Messages.insert({
name: "[Server]",
message: "<div class='animated infinite flash'>Attention! Chat will be cleared in 15 seconds!<br>Note: Chat is cleared every 12 hours</div>",
time: moment().format('MMMM Do , h:mm a'),
uid: Messages.find().fetch().length + 1,
email: "Server Function"
});
Meteor.setTimeout(function () {
Messages.remove({});
}, 15000);
}, 28800000);
time = 28000000; //Sets the ammount of time to countdown
uid = 0;
Meteor.setInterval(function(){ //The part that allows the client to see it
console.log(uid);
timeToClear.insert({
time: time,
uid: uid
})
time = time - 1000;
uid = uid + 1;
if(time === 0){
time = 28000000; //Resets time after countdown is complete
uid = 0;
timeToClear.remove({}); //Removes all previous time calls
}
}, 1000)
Client:
Template.countdown.helpers({
timer: function (){
x = timeToClear.find({}, { sort: { uid: -1}}).fetch()[0].time; //Gets the highest (newest) uid, and gets the time from it
var tempTime = moment.duration(x); //Converts it into a nicer format using moment
var hours = tempTime.hours();
var minutes = tempTime.minutes();
var seconds = tempTime.seconds();
return "Time till messages are cleared: " +hours + ":" + minutes + ":" + seconds; //Returns it to helper
}
})
Then simply call the helper on the client in a template called countdown!