The ST_AddPoint function is implemented in GeoDjango? - sql

Actually have a LineStringField on my model, and need actualize this field every 15 seconds, i have a total of 300 points, this represent a problem in the asynchronous performance?.

Related

Create a variable to count from 1 to n in AnyLogic

I am looking to add a variable to count from 1 to 217 every hour in AnyLogic, in order to use as a choice condition to set a parameters row reference.
I am assuming I either need to use an event or a state chart however I am really struggling with the exact and cannot find anything online.
If you have any tips please let me know, any help would be appreciated
Thank you,
Tash
A state machine isn't necessary in this case as this can be achieve using a calculation or a timed event. AnyLogic has time() function which returns time since model start as a double in model time units of measurements.
For example: if model time units is seconds and it has been running for 2hr 2min 10sec then time(SECOND) will return 7330.0 (it is always a double value). 1/217th of an hour corresponds to about 3600/217 = 16.58 seconds. Also, java has a handy function Math.floor() which rounds down a double value, so Math.floor(8.37) = 8.0.
Assembling it all together:
// how many full hours have elapsed from the start of the model
double fullHrsFromStart = Math.floor(time(HOUR));
// how many seconds have elapsed in the current model hour
double secondsInCurrentHour = time(SECOND) - fullHrsFromStart * 3600.0;
// how many full 16.58 (1/217th of an hour) intervals have elapsed
int fullIntervals = (int)(secondsInCurrentHour / 16.58);
This can be packaged into a function and called any time and it is pretty fast.
Alternatively: an Event can be created which increments some count by 1 every 16.58 seconds and ten resets it back to 0 when the count reaches 217.

How to make an object appear after a specific amount of time in Processing

Im trying to make a program where you are a ship and you simply avoid comets that fly towards you. I somewhat know how to use array lists to add and subtract objects, but I'm not sure how to get the program to add and subtract objects after a specific time like 5 seconds. My goal is to make each comet spawn 2 seconds apart but I'm not sure how. If anyone can help please let me know!
Processing exposes a useful variable frameCount that you can use for such timing behaviours.
You could use it in combination with the modulo operator % (an operator that returns the remainder after the division of two numbers), as follows:
draw() {
.
.
.
if (frameCount % t == 0) {
spawnComet();
}
.
.
.
}
Assuming frameRate is fixed at 60, t takes the value of 60*(desired time delay in seconds). You want to spawn comets every 2 seconds: 60*2 = 120. Therefore set t to 120 to satisfy the requirement of your example. This means spawnComet() will trigger every 120 frames.

Callgrind - QCachegrind output: Does "self" represents the cost of a function per call?

I am confused as to how to interpret the "Self" slot in QCachegrind. Is it per call cost of a function or is it the total cost of a function when called x times where x is represented by the slot "called"?
(please see the image below)
Is 0.003 the cost of function when called once? or do I need to divide it by 2 ("called" slot) to get the function cost per call?
I was also looking for this answer also, found out that the Self that shows 0.003 is the cost for ALL the "Called". So for each call cost, theoretically it cost 0.003 / 2 . Although I think it's not that simple because different call to the same function can have different cost.
Incl. is the total cost of the function on that line, including the cost of all the functions called directly or indirectly by this function.
Self is the cost of the function itself.
See http://www.valgrind.org/docs/manual/cl-manual.html#cl-manual.use
(in particular section 6.1.1. Functionality) for more details.

Trimming sorted set by score

In a Django app, I use redis to maintain a global sorted set where user ids are stored with the score of current time since epoch.
After every 11 minutes, I am to run an asynchronous task that trims the sorted set to solely values that were saved in the previous 10 minutes, nothing beyond.
Would the following accomplish this? I'm unsure about edge cases (e.g. will this ensure all old values are deleted or will some leak, etc.):
time_now = time.time() #current time since epoch
ten_mins_ago = time_now - (10*60)
eleven_mins_ago = time_now - (11*60)
my_redis_server.zremrangebyscore(sorted_set,eleven_mins_ago,ten_mins_ago)
Replace eleven_mins_ago with the string value -inf to delete everything that's older than 10 minutes and to avoid any "leak"age. Refer to the Exclusive intervals and infinity section of the ZRANGE's documentation page for full details and explanation.

Static timed loop in objective-c cocos2d?

Looking for some ideas on how to implement this, don't necessarily need the exact code.
Let's say I have a game where the player's hit points are displayed in a label, say 100HP. When he takes damage, say 30 damage, I want that label to count down from 99, 98 , 97 ... 70. It should take 2 seconds to perform the countdown whether you take 30 damage or 3000 damage.
I'm wondering what's the most efficient way to get this loop to count down "smoothly" over 2 seconds no matter what the damage taken is.
I'd probably extend a CCLabelSomething to do that, embedding the desired behaviour. Suggest a fixed width font, otherwise nothing smooth will happen (visually). Figure out what is 'smooth for you', ie how many updates in the 2 second period. in the assumed 'setScore' public method, start a scheduled update cycle with appropriate delay. In the schedule callback, change the text of the label.
say 20 updates, ie 10 per seconds. Schedule with .1f delay between intervals. Upon setScore, compute the 'delta' per update (currentScore - newScore)/20. Decrement currentScore down to newScore by this delta. In the schedule callBack, stop your scheduled update if the displayed score is equal to the newScore.