Skip to content

Commit

Permalink
Display agreements (#1762)
Browse files Browse the repository at this point in the history
* Import list of agreements with policies

- Agreements live in json and are associated with policies
- Display agreements in detailed policy page
- Uses date range to only show relevant agreements for an MP
  • Loading branch information
ajparsons authored Feb 22, 2024
1 parent 6fa404c commit ae6b735
Show file tree
Hide file tree
Showing 9 changed files with 535 additions and 123 deletions.
2 changes: 2 additions & 0 deletions classes/Policies.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function __construct($policy_id = null) {
6672,
);

$this->all_policy_agreements = $policy_data['agreements'] ?? [];

if ( $policy_id ) {
$this->policy_id = $policy_id;
$this->policies = array(
Expand Down
27 changes: 27 additions & 0 deletions scripts/json2db.pl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,33 @@ sub fetch_policies {
$out->{policies}{$policy->{id}} = $policy->{context_description};
}

# get agreement information to store in the json
# agreements by definition don't have anything specific for indiv MPs
# so can be just be simply stored for reference in policy page.
my $out_agreements = {};

foreach my $policy (@{$policies->{policies}}) {
my $policy_id = $policy->{"id"};
foreach my $agreement (@{$policy->{"agreement_links"}}) {
my $decision = $agreement->{"decision"};
my $chamber = $decision->{"chamber"};
my $data = {
"house" => $chamber->{"slug"},
"date" => $decision->{"date"},
"gid" => $decision->{"date"} . $decision->{"decision_ref"},
"url" => $decision->{"twfy_link"} =~ s/https:\/\/www.theyworkforyou.com//r,
"division_name" => $decision->{"division_name"},
"strength" => $agreement->{"strength"},
"alignment" => $agreement->{"alignment"},
};
push(@{$out_agreements->{$policy_id}}, $data);
};
};

# add the agreements to the output
$out->{agreements} = $out_agreements;


$out = $json->encode($out);
open(my $fp, '>', mySociety::Config::get('RAWDATA') . '/scrapedjson/policies.json');
$fp->write($out);
Expand Down
16 changes: 16 additions & 0 deletions tests/DivisionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ public function testSinglePolicy() {

}

public function testMPPageContainsAgreement()
{
// Checks this MP contains a reference to the agreement
$page = $this->fetch_page( array( 'pagetype' => 'divisions', 'pid' => 2, 'policy' => 363, 'url' => '/mp/2/test_current-mp/test_westminster_constituency/divisions' ) );
$this->assertStringContainsString('Example Agreement', $page);
}

public function testMPPageDoesNotContainsAgreement()
{
// Checks this MP does not contain agreement - should be out of time scope
$page = $this->fetch_page( array( 'pagetype' => 'divisions', 'pid' => 6, 'policy' => 363, 'url' => '/mp/6/test_current-mp/test_westminster_constituency/divisions' ) );
$this->assertStringNotContainsString('Example Agreement', $page);
$this->assertStringNotContainsString('This person has not voted on this policy', $page);

}

public function testVoteDirection() {
$page = $this->fetch_division_page();
$this->assertStringContainsString('Test Current-MP voted Agreed', $page);
Expand Down
161 changes: 161 additions & 0 deletions tests/_fixtures/divisions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@
<field name="person_id">5</field>
<field name="lastupdate">2013-08-07 11:15:47</field>
</row>
<row>
<field name="member_id">5</field>
<field name="house">1</field>
<field name="constituency">Test Westminster Constituency</field>
<field name="party">XB</field>
<field name="entered_house">2000-01-01</field>
<field name="left_house">2015-01-01</field>
<field name="entered_reason">appointed</field>
<field name="left_reason">retired</field>
<field name="person_id">6</field>
<field name="lastupdate">2013-08-07 15:06:22</field>
</row>
</table_data>
<table_data name="person_names">
<row>
Expand Down Expand Up @@ -91,6 +103,14 @@
<field name="person_id">5</field>
<field name="title">Ms</field>
</row>
<row>
<field name="given_name">Test</field>
<field name="family_name">Current-MP</field>
<field name="start_date">2000-01-01</field>
<field name="end_date">2015-01-01</field>
<field name="person_id">6</field>
<field name="title">Mrs</field>
</row>
</table_data>
<table_data name="persondivisionvotes">
<row>
Expand Down Expand Up @@ -202,6 +222,117 @@
<field name="person_id">2</field>
<field name="division_id">pw-3012-01-01-1-commons</field>
<field name="vote">aye</field>
</row>

<row>
<field name="person_id">6</field>
<field name="division_id">pw-2013-01-01-1-commons</field>
<field name="vote">Yes</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2013-01-01-2-commons</field>
<field name="vote">No</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2013-01-01-3-commons</field>
<field name="vote">absent</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2013-01-01-4-commons</field>
<field name="vote">both</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2013-01-01-5-commons</field>
<field name="vote">yes</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2013-01-01-6-commons</field>
<field name="vote">no</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2013-01-01-7-commons</field>
<field name="vote">tellno</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2013-01-01-8-commons</field>
<field name="vote">tellaye</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2012-01-01-1-commons</field>
<field name="vote">Yes</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2012-01-01-2-commons</field>
<field name="vote">Yes</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2012-01-01-3-commons</field>
<field name="vote">Yes</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2012-01-01-4-commons</field>
<field name="vote">Yes</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2012-01-01-5-commons</field>
<field name="vote">Yes</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2012-01-01-6-commons</field>
<field name="vote">Yes</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2012-01-01-7-commons</field>
<field name="vote">Yes</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2012-01-01-8-commons</field>
<field name="vote">Yes</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2012-01-01-9-commons</field>
<field name="vote">Yes</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2012-01-01-10-commons</field>
<field name="vote">Yes</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2012-01-01-11-commons</field>
<field name="vote">Yes</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2012-01-01-12-commons</field>
<field name="vote">Yes</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-2012-01-01-13-commons</field>
<field name="vote">Yes</field>
</row>
<row>
<field name="person_id">6</field>
<field name="division_id">pw-3012-01-01-1-commons</field>
<field name="vote">aye</field>
</row>
</table_data>
<table_data name="memberinfo">
Expand Down Expand Up @@ -235,6 +366,36 @@
<field name="data_key">public_whip_dreammp810_has_strong_vote</field>
<field name="data_value">0</field>
</row>
<row>
<field name="member_id">5</field>
<field name="data_key">public_whip_dreammp363_distance</field>
<field name="data_value">0.87</field>
</row>
<row>
<field name="member_id">5</field>
<field name="data_key">public_whip_dreammp363_both_voted</field>
<field name="data_value">8</field>
</row>
<row>
<field name="member_id">5</field>
<field name="data_key">public_whip_dreammp363_has_strong_vote</field>
<field name="data_value">1</field>
</row>
<row>
<field name="member_id">5</field>
<field name="data_key">public_whip_dreammp810_distance</field>
<field name="data_value">0.87</field>
</row>
<row>
<field name="member_id">5</field>
<field name="data_key">public_whip_dreammp810_both_voted</field>
<field name="data_value">1</field>
</row>
<row>
<field name="member_id">5</field>
<field name="data_key">public_whip_dreammp810_has_strong_vote</field>
<field name="data_value">0</field>
</row>
</table_data>
<table_data name="policies">
<row>
Expand Down
Loading

0 comments on commit ae6b735

Please sign in to comment.