help needed in making a "n" minute timer macro

222 views
Skip to first unread message

cpedia...@gmail.com

unread,
Dec 10, 2017, 2:00:05 AM12/10/17
to TiddlyWiki
I dont know how to make this happen but i saw some code here

Could some one help me out in making a widget/macro for this purpose?

it would be also good to get the minutes and seconds in seperate temp tiddlers as the timer progresses so that after a particular time has passed some action can be made to happen ..

PMario

unread,
Dec 10, 2017, 5:57:43 AM12/10/17
to TiddlyWiki
On Sunday, December 10, 2017 at 8:00:05 AM UTC+1, cpedia...@gmail.com wrote:
it would be also good to get the minutes and seconds in seperate temp tiddlers as the timer progresses so that after a particular time has passed some action can be made to happen ..

IMO you need to be a bit more specific, about what you want.

Do you want 1 timer or several active at the same time?
Should they be pausable / deletable while active?
What "action" do you want, after the timer has stopped?
What should happen, if the tab, that contains the timer is not visible?

ToDoNow plugin contains something that's called a "deadline" https://tid.li/tw5/plugins.html
Do you want something like this?

-m

cpedia...@gmail.com

unread,
Dec 11, 2017, 2:42:18 AM12/11/17
to TiddlyWiki
hey Pmario,

Sorry abt the lack of clarity, I shall explain.

Use Case: some sort of quizzing platform where a countdown is initiated once the quiz starts and once the time is up navigate to a tiddler where responses can be submitted

I tried doing something in the last few hours (I have no idea abt javascript but somehow managed by looking at other examples, most notably http://tiddlytime.tiddlyspot.com/)




/*\
title: $:/plugins/timer.js
type: application/javascript
module-type: macro

\*/
(function () {

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

// Export name and synchronous status
exports.name = "timer";
exports.params = [];

exports.run = function() {
// Set the date we're counting down to
var countDownDate = new Date().getTime();

// Update the count down every 1 second
var x = setInterval(function() {

  // Get todays date and time
  var now = new Date().getTime();

  // Find the distance between now an the count down date
  var distance = now - countDownDate;

  // Time calculations for days, hours, minutes and seconds
  var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  var seconds = Math.floor((distance % (1000 * 60)) / 1000);

  return new $tw.Tiddler($:/temp/time,{"text": days + "d " + hours + "h " + minutes + "m " + seconds + "s "});

  // If the count down is over, write some text 
    if (distance > 60000) {
        clearInterval(x);
  return new $tw.Tiddler($:/temp/timeup,{"text": Time Up});
    }
    
}, 1000);
};

})();


cheers



PMario

unread,
Dec 11, 2017, 3:23:07 AM12/11/17
to TiddlyWiki
On Monday, December 11, 2017 at 8:42:18 AM UTC+1, cpedia...@gmail.com wrote:
Use Case: some sort of quizzing platform where a countdown is initiated once the quiz starts

That's interesting and something completely different, to my thoughts :)
 
and once the time is up navigate to a tiddler where responses can be submitted

ok
 
I tried doing something in the last few hours (I have no idea abt javascript but somehow managed by looking at other examples, most notably http://tiddlytime.tiddlyspot.com/)

I didn't test your code. ... Does it work as expected?

-m

cpedia...@gmail.com

unread,
Dec 11, 2017, 3:43:55 AM12/11/17
to TiddlyWiki
Nope it doesnt .. lots of warnings come up :(

However i was able to manipulate the $:/plugins/ajh/tiddlytime/time.js in http://tiddlytime.tiddlyspot.com/ and was able to get a 1 minute countdown timer that displays into {{$:/temp/timer}} and shows"Time Up" at the end of the countdown ..

problem is i dont know how to convert this to a javascript macro .. also the stop watch works from upon startup and i guess this must be because of exports.startup .. but when i tried to make it exports.run it didnt work as a macro ..

I have attached the working sample check it out and let me know :)
timertest.html

cpedia...@gmail.com

unread,
Dec 11, 2017, 3:44:50 AM12/11/17
to TiddlyWiki
Not stop watch ..i meant countdown timer ,,..

PMario

unread,
Dec 11, 2017, 4:35:45 AM12/11/17
to TiddlyWiki
On Monday, December 11, 2017 at 9:43:55 AM UTC+1, cpedia...@gmail.com wrote:
Nope it doesnt .. lots of warnings come up :(

OK ... We are all very "implementation oriented" ... My problem now is, that you didn't answer any of my questions.
Since the code doesn't do what you want, imo we need to go back to the whiteboard and define what's needed.

I can only guess from what you wrote.

some sort of quizzing platform where a countdown is initiated once the quiz starts and once the time is up navigate to a tiddler where responses can be submitted

 - Do you want 1 timer or several active at the same time?

Since you want to convert the function to macros ... probably several are active at the same time.


 - Should they be pausable / deletable while active?

In a quiz situation I personally would want to have a possibility to stop a timer, if I know the answer. ... But that's just me ;)  Your usecase may be completely different, to my thoughts.


 - What "action" do you want, after the timer has stopped?

It seems there should be just the text "Time is over" ... But if I can't stop it, every timer will run into this state. ... ??

 - What should happen, if the tab, that contains the timer is not visible?

Many browsers treat code in "inactive" tabs different to code in active tabs. ... So we may need to take care of this ...

--------------

However i was able to manipulate the $:/plugins/ajh/tiddlytime/time.js in http://tiddlytime.tiddlyspot.com/ and was able to get a 1 minute countdown timer that displays into {{$:/temp/timer}} and shows"Time Up" at the end of the countdown ..

That's great, for someone who is not familar with javascript :)
 
problem is i dont know how to convert this to a javascript macro

IMO widget. ... I think, we need interaction
 
.. also the stop watch works from upon startup and i guess this must be because of exports.startup .. but when i tried to make it exports.run it didnt work as a macro ..

ok. ... That's not the way how it works. ...
 
I have attached the working sample check it out and let me know :)

I don't have the time to dig into it atm. ...

But the usecase is definitely interesting. .. Quizzes are always interesting, and I think we don't have a countdown functionality / plugin atm.

So someone else ???

have fun!
mario

cpedia...@gmail.com

unread,
Dec 11, 2017, 5:23:34 AM12/11/17
to TiddlyWiki
ah .. so much to know :) .. thank you so much for your thoughts .. 

My quizzing platform is to be like this:

Landing page where you type in name and click "Start Test" 

When you click "Start Test" the following happens:
1. Countdown timer starts in right hand corner above sidebar (or somewhere else visible)
2. a timestamp (say ts1) is generated
3. You navigate to Question no.1

Answer the Question no.1 (this choice is recorded in a the field of a state tiddler) and click "Next Question"

When you click "Next Question" the following happens:
1. a timestamp (say ts2)is generated
2. You navigate to Question no.2

Now ts2 - ts1 will give the time taken to answer question 1

So on... 

All this while .. the countdown timer (above sidebar) continues and if it becomes 00:00 then irrespective of how many questions are left to be answered it takes you to the "Submit Answers" tiddler which once pressed will do the following:

1. check the answers submitted with an answer key and sort out neatly the answers answered correctly/wrongly/unanswered and you can check out the solutions for each
2. calculate the score
3. send the score and the submitted answers to a google spreadsheet by way of the submit form plugin (by Jed? i guess)

So once all have taken the test a ranking can be developed from the data collected in the google sheet and published ....

But a countdown plugin can have much more usecases .. for example in the ToDoNow itself we can start a task and the timer starts and once the task is complete the timer stops and is recorded

Or even in the Kanban plugin the time a task spent in any category can be noted down etc....

you are right ..  much thought must be spent on making a countdown plugin as universal as possible .. looking at all possible use cases  .. 

@TiddlyTweeter

unread,
Dec 11, 2017, 6:11:52 AM12/11/17
to TiddlyWiki
We seriously need a TIME & TIMING section better documented.

I'm not able to help you solve this but I do know there has been lots of stuff done on timing.

I did see a countdown made by someone in a quiz. I just can't find it.

Its somewhere.

Best wishes
Josiah

PMario

unread,
Dec 11, 2017, 6:32:33 AM12/11/17
to TiddlyWiki
On Monday, December 11, 2017 at 11:23:34 AM UTC+1, cpedia...@gmail.com wrote:
My quizzing platform is to be like this:

 ... I think that's a description we can work with ;)

-m

cpedia...@gmail.com

unread,
Dec 11, 2017, 7:03:14 AM12/11/17
to TiddlyWiki
heyyyy i think after a lot of quarelling with the computer i made something workable sort off ..  check attachment .. 

its a very crude solution and i am sure i am gonna outrage code puritans ;) ....
timertest.html

@TiddlyTweeter

unread,
Dec 11, 2017, 7:20:39 AM12/11/17
to TiddlyWiki
Well it counts UP :-) And doesn't reset when you click the "Start Timer". But definitely looks in the general direction on the counter part of your project.

J x
Reply all
Reply to author
Forward
0 new messages