Editing Maemo.org team/Creating an election

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 78: Line 78:
: The schema is:
: The schema is:
-
<source lang="sql">
+
    DROP TABLE IF EXISTS `electorate`;
-
DROP TABLE IF EXISTS `electorate`;
+
    /*!40101 SET @saved_cs_client = @@character_set_client */;
-
/*!40101 SET @saved_cs_client = @@character_set_client */;
+
    /*!40101 SET character_set_client = utf8 */;
-
/*!40101 SET character_set_client = utf8 */;
+
    CREATE TABLE `electorate` (
-
CREATE TABLE `electorate` (
+
    `id` int(11) NOT NULL AUTO_INCREMENT,
-
`id` int(11) NOT NULL AUTO_INCREMENT,
+
    `username` varchar(20) DEFAULT NULL,
-
`username` varchar(20) DEFAULT NULL,
+
    `firstname` varchar(50) NOT NULL DEFAULT '',
-
`firstname` varchar(50) NOT NULL DEFAULT '',
+
    `lastname` varchar(50) NOT NULL DEFAULT '',
-
`lastname` varchar(50) NOT NULL DEFAULT '',
+
    `email` varchar(50) NOT NULL DEFAULT '',
-
`email` varchar(50) NOT NULL DEFAULT '',
+
    `karma` int(11) NOT NULL DEFAULT '0',
-
`karma` int(11) NOT NULL DEFAULT '0',
+
    `creation_date` datetime DEFAULT NULL,
-
`creation_date` datetime DEFAULT NULL,
+
    `talk_id` varchar(70) DEFAULT NULL,
-
`talk_id` varchar(70) DEFAULT NULL,
+
    PRIMARY KEY (`id`)
-
PRIMARY KEY (`id`)
+
    ) ENGINE=MyISAM AUTO_INCREMENT=32822 DEFAULT CHARSET=latin1;
-
) ENGINE=MyISAM AUTO_INCREMENT=32822 DEFAULT CHARSET=latin1;
+
    /*!40101 SET character_set_client = @saved_cs_client */;
-
/*!40101 SET character_set_client = @saved_cs_client */;
+
    /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
-
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
+
-
</source>
+
; Create election in the database
; Create election in the database
Line 102: Line 100:
  insert into elections values(10, 'elections', 'Maemo Community Council elections, Q3 2010', '2010-09-16 00:00:00', '2010-09-22 23:59:59', 5, 'In order of preference, which of the following candidates do you want to represent you on the Maemo Community Council?');
  insert into elections values(10, 'elections', 'Maemo Community Council elections, Q3 2010', '2010-09-16 00:00:00', '2010-09-22 23:59:59', 5, 'In order of preference, which of the following candidates do you want to represent you on the Maemo Community Council?');
   
   
-
<source lang="sql">
+
/* Fields are id, election id, name - id is auto-increment */
-
/* Fields are id, election id, name - id is auto-increment */
+
insert into election_choices values
-
insert into election_choices values
+
   (0, 10, 'Andrea Grandi (andy80)'),
   (0, 10, 'Andrea Grandi (andy80)'),
   (0, 10, 'Tim Samoff (timsamoff)'),
   (0, 10, 'Tim Samoff (timsamoff)'),
Line 115: Line 112:
   (0, 10, 'Kathy Smith (revdkathy)'),
   (0, 10, 'Kathy Smith (revdkathy)'),
   (0, 10, 'Attila Csipa (achipa)')
   (0, 10, 'Attila Csipa (achipa)')
-
;
+
;
-
</source>
+
; Insert electorate into database
; Insert electorate into database
: Insert the rows into your database using the following (note, we ignore the talk profile URL now, but there is still a column for it in the database):
: Insert the rows into your database using the following (note, we ignore the talk profile URL now, but there is still a column for it in the database):
-
 
+
/* Truncate old electorate table and old temp tokens */
-
<source lang="sql">
+
truncate electorate;
-
/* Truncate old electorate table and old temp tokens */
+
truncate election_tmp_tokens;
-
truncate electorate;
+
-
truncate election_tmp_tokens;
+
   
   
-
/* Load data file using LOAD DATA INFILE (or mysqlimport) */
+
/* Load data file using LOAD DATA INFILE (or mysqlimport) */
-
load data local infile '/path/to/data/users.csv' into table electorate
+
load data local infile '/path/to/data/users.csv' into table electorate
   fields terminated by ',' optionally enclosed by '"'
   fields terminated by ',' optionally enclosed by '"'
   (username,@dummy,firstname,lastname,@email,creation_date,karma,@talk)
   (username,@dummy,firstname,lastname,@email,creation_date,karma,@talk)
   set email=substring_index(@email,';',1),  
   set email=substring_index(@email,';',1),  
       talk_id=substring_index(@talk,'=',-1)
       talk_id=substring_index(@talk,'=',-1)
-
;
+
;
-
/* This is a complicated line, worth explaining.
+
/* This is a complicated line, worth explaining.
-
* LOAD DATA INFILE basically does a series of inserts, one for each  
+
  * LOAD DATA INFILE basically does a series of inserts, one for each  
-
* line of data in the input file.
+
  * line of data in the input file.
-
* The part in brackets matches fields or variables to entries in the  
+
  * The part in brackets matches fields or variables to entries in the  
-
* data line, with separator, quote and line ending bevahiour as specified.
+
  * data line, with separator, quote and line ending bevahiour as specified.
-
* We drop the "Real name" field. The email field contains semi-colon
+
  * We drop the "Real name" field. The email field contains semi-colon
-
* separated list of all the email addresses associated with the account,
+
  * separated list of all the email addresses associated with the account,
-
* so we search the field for a semicolon, and just take the first one.
+
  * so we search the field for a semicolon, and just take the first one.
-
* The talk field contains a URL with a talk_id after "=", which is what we
+
  * The talk field contains a URL with a talk_id after "=", which is what we
-
*  want, so we look for = and take everything after the first occurrence.
+
  *  want, so we look for = and take everything after the first occurrence.
-
*/
+
  */
   
   
-
/* Delete from electorate anyone with insufficient karma */
+
/* Delete from electorate anyone with insufficient karma */
-
delete from electorate where karma < 10;
+
delete from electorate where karma < 10;
-
/* Delete accounts created too recently (3 months before end of election) */
+
/* Delete accounts created too recently (3 months before end of election) */
-
delete from electorate where creation_date > '2010-06-23';
+
delete from electorate where creation_date > '2010-06-23';
-
</source>
+
It is also possible to filter on older talk_ids, even if the maemo account was created recently. Ask Reggie for the cut-off Talk user id for the electorate date, and include the cut-off in the "delete from" for recently created accounts.
It is also possible to filter on older talk_ids, even if the maemo account was created recently. Ask Reggie for the cut-off Talk user id for the electorate date, and include the cut-off in the "delete from" for recently created accounts.

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)