Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display agreements #1762

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -96,6 +96,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 @@ -110,6 +110,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 @@ -144,6 +156,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 @@ -255,6 +275,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 @@ -288,6 +419,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="mentions">
</table_data>
Expand Down
Loading
Loading