collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18366
  • stats Total Topics: 2501
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: Voting module (over seconds or minutes, not days)  (Read 7512 times)

0 Members and 1 Guest are viewing this topic.

Offline Areteh

  • BeBot User
  • **
  • Posts: 23
  • Karma: +0/-0
Voting module (over seconds or minutes, not days)
« on: July 31, 2006, 03:35:01 pm »
Well, I accidentally trained a bunch of mobs on to the opposing side in pande, so I figured that I'd try to apologize by way of code.  So I finished off everything on todo, and here are the results.

// Instructions:
// To start a vote,
//   !vote start <question>? <choice 1> <choice 2> ...
//   The question must end with a question mark, and contain no question marks within it.
//   The choices must be single words, seperated by a single space between each word.
// To cancel a vote,
//   !vote cancel <optional reason>
// To terminate a vote early and display results,
//   !vote end <optional reason>
// To display the last vote's results,
//   !vote results
// To display the vote history
//   !vote history
// To display the vote history details of a particular vote
//   !vote history <number>
// To change the output channel,
//   !vote output <gc|pgmsg|both>
// To place a vote
//   !placevote <number>
// To adjust the running time of votes
//   !vote length <number>
// To adjust the interval between messages to chat
//   !vote interval <number>
///////////////////////////////////
// Changelog:
// 2.1
//  * Fixed to use 2 sec cron instead of 1 sec cron, as 1 sec cron isn't fully supported
//  * Now has an internal counter for keeping track of time elapsed, to fix issues where cron
//   is called multiple times in the same second, or not called during certain seconds.
// 2.0
//  * Changed it to announce once per 20 seconds instead of once per 10 seconds
//  * !vote interval to adjust how often we announce to chat
//  * Fixed bug where "vote now" would appear multiple times in one interval
//  * Set cron dynamically when a vote is started.  (Thanks Snowsy!)
//  * Save and load settings between bot restarts
//  * !vote history, and changed !vote result to use DB
//  * Started using <botname> and <pre> where appropriate
//  * Helpfile updated
// 1.1
//  * Wrote a help file
//  * Added vote length adjustment
//  * Command responses are now sent to the same channel as the command was issued (where applicable).
//  * Added responses to some commands to show that they worked.
// 1.0
//  * First Version, includes start, cancel, end, results, output, and placevote
--
2.1 uploaded
« Last Edit: January 03, 2007, 04:30:48 pm by Areteh »

Offline Sammajos

  • BeBot Rookie
  • *
  • Posts: 9
  • Karma: +0/-0
Re: Voting module (over seconds or minutes, not days)
« Reply #1 on: August 02, 2006, 05:04:02 pm »
Waaaaahhhhhhh,


thx Areteh. Now i can put it into the Bots  ;D
« Last Edit: August 02, 2006, 05:57:46 pm by Sammajos »

Offline Pharexys

  • BeBot Apprentice
  • ***
  • Posts: 117
  • Karma: +0/-0
Re: Voting module (over seconds or minutes, not days)
« Reply #2 on: August 03, 2006, 03:35:44 pm »
nice one, im gonn edit it to fet my needs, nice work btw ;D

Offline jjones666

  • Contributor
  • *******
  • Posts: 353
  • Karma: +0/-0
Re: Voting module (over seconds or minutes, not days)
« Reply #3 on: November 17, 2006, 02:13:58 am »
Hmm, cron[1sec] no longer exists in bebot 0.2.9 (does in 0.3.x).  If you change to cron[2sec], nothing works at all (no output to GC etc), so I couldn't figure out how to fix it :-/  Obviously with no cron working the vote itself does work but is infinite and has to be cancelled manually.

Any tips anybody?

Cheers,

-jj-


Offline Areteh

  • BeBot User
  • **
  • Posts: 23
  • Karma: +0/-0
Re: Voting module (over seconds or minutes, not days)
« Reply #4 on: January 03, 2007, 04:34:22 pm »
I uploaded a new version that uses 2 sec cron.  Also, a minor fix that should help heavily loaded bots display properly, at the cost of reduced (theoretical) accuracy in voting time calculation in some unusual cases.

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: Voting module (over seconds or minutes, not days)
« Reply #5 on: January 03, 2007, 08:47:00 pm »
No one should ever need to run a vote with 1 second accuracy.
I'd argue that even using 2 seconds is overkill in this case :)
BeBot Founder and Fixer Kingpin

Offline Areteh

  • BeBot User
  • **
  • Posts: 23
  • Karma: +0/-0
Re: Voting module (over seconds or minutes, not days)
« Reply #6 on: January 05, 2007, 01:21:10 pm »
This is all pedantic detail that I don't think anyone but a programmer would care about, and even that's a bit iffy.  So, feel free to ignore this post.

Anyway, I'll explain the gritty details about my statement above.  The vote module sends a textbox link to chat every 20 seconds (configurable) indicating that the vote is still running.  The previous version used 1 sec cron, and checked delta time started and current time.  In some cases, under a heavily loaded bot, bebot seems to have multiple cron calls in the same second.  If this occurred during the 20 second time when the module was supposed to show the voting booth, it would spam private group rather nastily.  In other cases, it would skip that particular second entirely, and no "vote in progress, click here" message would appear at all.

The fix uses a counter to count elapsed time, and assumes that bebot is honest about the cron timer for accuracy.  So, with the 2 second tick, it will spam at 10 ticks, and again at 20 ticks, and complete at 30 ticks.  So, theoretically, this would produce the same result (a single text box every 20 seconds), in practice the timing may be slightly off, but it's close enough to make no difference.

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: Voting module (over seconds or minutes, not days)
« Reply #7 on: January 06, 2007, 03:19:32 pm »
I'll explain my statement briefly.

The reason one should always try to use as long intervals as possible is because it helps prevent the situation described above where a bot ends up having too much to do at any given time. A vote could happily be accurate to within 5 seconds imho and it not cause any issues. But at the same time, it over halves the load the script causes to the bot simply by the cron being called only 12 times per minute instead of 30 times per minute.

These differences seem insignificant on their own, but once you start having 50 different scripts doing it the "bad way" at the same time, it starts to make a difference.

As for the load issue, it could probably be possible to help ease the problem some more by rewriting the entire cron system to be more an "event" system so that every 2 second cron isn't run at the same second, and every 5 second cron isnt run at the same second etc by using a random delay on first register of a new event.
BeBot Founder and Fixer Kingpin

Offline Areteh

  • BeBot User
  • **
  • Posts: 23
  • Karma: +0/-0
Re: Voting module (over seconds or minutes, not days)
« Reply #8 on: January 08, 2007, 08:34:38 pm »
Well, it sends a message to group every 20 (configurable) seconds stating that the vote is open.  An ideal solution would be cron with completely variable scheduling, instead of hard coded 2 seconds or whatnot.  That can only be done with some overhead that I'm not sure is worth the gain.  As is, I don't see a way to keep the click to vote spam without the admittedly overly short cron.

With that said, I set the cron dynamically when the vote starts, and clear it when the vote is over, so the performance hit should be minimal, and only occur during a vote.  If every module does that, then there won't be much of an issue because only a few modules will have a cron at any particular time.

That's my opinion, of course, feel free to prove me wrong.

Offline Wolfbiter

  • Contributor
  • *******
  • Posts: 149
  • Karma: +0/-0
    • KAZE
Re: Voting module (over seconds or minutes, not days)
« Reply #9 on: January 08, 2007, 10:03:35 pm »
As for the load issue, it could probably be possible to help ease the problem some more by rewriting the entire cron system to be more an "event" system so that every 2 second cron isn't run at the same second, and every 5 second cron isnt run at the same second etc by using a random delay on first register of a new event.

http://bebot.link/index.php/topic,525.0.html - No random delay, but more of an event system to cron.
Too many toons.

Offline lulifuz

  • BeBot User
  • **
  • Posts: 40
  • Karma: +0/-0
Re: Voting module (over seconds or minutes, not days)
« Reply #10 on: January 17, 2007, 08:30:08 pm »
Hi there,

found this and wanted to make it run on our bot (2.9).
But it only sends Messages to PrivGrp.
Any idea?

[Edit]
Ok, shame on me. Does not work in tells to the Bot.  :-\
Sorry, works fine, ever did, I think.

But one thing regarding the database settings.
I think there is an error:
Code: [Select]
$results = $this -> bot -> db -> select("SELECT `setting`, `value` FROM settings WHERE setting='VoteTimer'");
if (!empty($results))
{
$this -> output_to = $results[0][1];
$this -> bot -> db -> query("INSERT INTO settings (`setting`, `value`) VALUES ('VoteOutput', 'pgmsg')");
}
There is at first a check for 'VoteTimer' but than an INSERT for 'VoteOutput'. Should this not be 'VoteTimer' too?
[/EDIT]

Regards,

 lulifuz
« Last Edit: January 18, 2007, 09:49:38 pm by lulifuz »

 

* Recent Posts
Com bot module by bitnykk
[November 25, 2024, 05:36:11 pm ]


0.8.x updates for AO by bitnykk
[June 23, 2024, 03:19:47 pm ]


0.8.x updates for AoC by bitnykk
[June 23, 2024, 03:19:44 pm ]


[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm ]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am ]

* Who's Online
  • Dot Guests: 325
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal