Skip to content

Commit

Permalink
Database: generate meetings data
Browse files Browse the repository at this point in the history
Create individual meeting records by reading times from Google Calendar events.  If there is no event for, the use the regularly scheduled time for each committee.

Updates #363
  • Loading branch information
inghamn committed Oct 10, 2024
1 parent f442d8a commit 84f47a5
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 5 deletions.
33 changes: 33 additions & 0 deletions scripts/migration/2.7-2.8/1_databaseChanges.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
alter table people drop authenticationMethod;
alter table people drop password;

drop table legislation_tags;
drop table tags;

create table meetings(
id int unsigned not null primary key auto_increment,
committee_id int unsigned not null,
meetingDate date not null,
datetime datetime,
eventId varchar(128),
foreign key (committee_id) references committees(id)
);

insert into meetings (committee_id, meetingDate, eventId)
select f.committee_id, f.meetingDate, f.eventId
from meetingFiles f
group by f.committee_id, f.meetingDate, f.eventId;

update meetings set eventId=null where datetime is null;

alter table meetingFiles add meeting_id int unsigned not null after committee_id;

update meetingFiles f
join meetings m on (f.committee_id=m.committee_id and f.meetingDate=m.meetingDate and f.eventId=m.eventId)
set f.meeting_id=m.id;

update meetingFiles f
join meetings m on (f.committee_id=m.committee_id and f.meetingDate=m.meetingDate and f.eventId is null and m.eventId is null)
set f.meeting_id=m.id;

alter table meetingFiles add foreign key (meeting_id) references meetings(id);
94 changes: 94 additions & 0 deletions scripts/migration/2.7-2.8/2_create_meeting_times.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
/**
* Populates meeting times in the new datetime field
*
* Sets meeting times from Google Events if they exist
* For meetings without Google Events, we use the standard meeting time for the committee
*
* @copyright 2024 City of Bloomington, Indiana
* @license https://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE
*/
declare (strict_types=1);
include '../../../src/Web/bootstrap.php';

use Application\Models\GoogleGateway;
use Web\Database;

$db = Database::getConnection();
$pdo = $db->getDriver()->getConnection()->getResource();
$log = fopen('./errors.csv', 'w');

$sql = 'update meetings set datetime=? where id=?';
$update = $pdo->prepare($sql);

$sql = "select m.id,
m.committee_id,
m.meetingDate,
m.eventId,
c.calendarId
from meetings m
join committees c on c.id=m.committee_id
where datetime is null
and eventId is not null";
$result = $pdo->query($sql, \PDO::FETCH_ASSOC);
foreach ($result as $row) {
echo "$row[id] $row[meetingDate] $row[eventId]\n";

try {
$e = GoogleGateway::getEvent($row['calendarId'], $row['eventId']);
$update->execute([$e->start->dateTime, $row['id']]);
}
catch (\Exception $e) { fputcsv($log, $row); }
}


// Regular meeting times for committees
$schedule = [
//1 => '', City council meeting times have changed over the years
3 => '18:00:00',
5 => '11:00:00',
9 => '17:00:00',
10 => '16:00:00',
13 => '12:00:00',
14 => '18:00:00',
16 => '16:00:00',
22 => '16:00:00',
25 => '17:30:00',
27 => '17:30:00',
28 => '17:00:00',
29 => '18:00:00',
31 => '16:30:00',
32 => '10:00:00',
33 => '12:00:00',
35 => '17:00:00',
36 => '16:30:00',
40 => '17:30:00',
46 => '13:30:00',
47 => '10:00:00',
49 => '00:00:00', // Sidewalk Committee meets at random times every meeting
55 => '10:00:00',
56 => '17:30:00',
57 => '17:30:00',
60 => '15:00:00',
62 => '17:30:00',
63 => '17:00:00',
68 => '18:00:00',
73 => '15:00:00',
];

$sql = "update meetings set datetime=concat_ws(' ', meetingDate, ?)
where datetime is null and committee_id=?";
$update = $pdo->prepare($sql);
foreach ($schedule as $committee_id=>$time) {
echo "$committee_id: $time\n";
$update->execute([$time, $committee_id]);
}

// City Council Meetings have been different standard times over the years
$sql = "update meetings set datetime=concat_ws(' ', meetingDate, ?)
where datetime is null
and meetingDate>?
and committee_id=?";
$update = $pdo->prepare($sql);
$update->execute(['18:30:00', '2017-01-01', 1]);
$update->execute(['19:30:00', '1950-01-01', 1]);
3 changes: 3 additions & 0 deletions scripts/migration/2.7-2.8/3_databaseChanges.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
alter table meetings drop meetingDate;
alter table meetings rename column datetime to start;
alter table meetings modify start datetime not null;
5 changes: 0 additions & 5 deletions scripts/migration/2.7-2.8/databaseChanges.sql

This file was deleted.

10 changes: 10 additions & 0 deletions scripts/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,18 @@ create table siteContent (
content text
);

create table meetings(
id int unsigned not null primary key auto_increment,
committee_id int unsigned not null,
start datetime not null,
eventId varchar(128),
foreign key (committee_id) references committees(id)
);

create table meetingFiles(
id int unsigned not null primary key auto_increment,
committee_id int unsigned not null,
meeting_id int unsigned not null,
meetingDate date not null,
eventId varchar(128),
type varchar(16) not null,
Expand All @@ -218,6 +227,7 @@ create table meetingFiles(
updated timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
indexed timestamp
foreign key (committee_id) references committees(id)
foreign key ( meeting_id) references meetings(id)
);

create table committeeHistory(
Expand Down

0 comments on commit 84f47a5

Please sign in to comment.