Skip to content
This repository has been archived by the owner on Jan 18, 2019. It is now read-only.

Commit

Permalink
identify village/.../block from position #26
Browse files Browse the repository at this point in the history
  • Loading branch information
Vikas Yadav committed Oct 17, 2017
1 parent be00b45 commit c154490
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 50 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ More than developing the software, we need to collect and cleanup data that we h
1. Markets:

## Updates
* **17-Oct-2017** - Local panchayat raj admins and elected reps support has started with Tamil Nadu. (:pushpin: v 0.7)
* **05-Oct-2017** - Gujarat, Assam data added
* **04-Oct-2017** - Much better looking site (:pushpin: v 0.6), Rajasthan and Arunachal Pradesh data added
* **03-Oct-2017** - West Bengal and Andra Pradesh data added
Expand Down
26 changes: 19 additions & 7 deletions protected/models/AssemblyPolygon.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class AssemblyPolygon extends CActiveRecord
var $ctr6;
var $ctr7;
var $ctr8;

var $ctr9;
var $ctr10;

/**
*
* @return string the associated database table name
Expand Down Expand Up @@ -80,6 +82,11 @@ public function relations()
self::BELONGS_TO,
'State',
'id_state'
),
'village' => array (
self::BELONGS_TO,
'LBVillage',
'id_village'
)
);
}
Expand Down Expand Up @@ -166,7 +173,7 @@ static function repACs()
$AR_table = AssemblyResults::model()->tableName();
$rs = AssemblyPolygon::model ()->findAll (
[
'group' => 'id_state,st_name,st_code',
'group' => 't.id_state,t.st_name,t.st_code',
'select' => "st_name,count(*) as ctr1,
(select count(name) from $AR_table r2 where r2.ST_CODE=t.ST_CODE) as ctr2,
(select count(phones) from $AR_table r3 where phones<>'' and r3.id_state=t.id_state) as ctr3,
Expand All @@ -175,7 +182,10 @@ static function repACs()
(select count(picture) from $AR_table r6 where picture<>'' and r6.id_state=t.id_state) as ctr6,
(select count(distinct id_city) from municipalresults r7 join towns2011 r7t on r7t.id_place=r7.id_city and r7t.tvtype in ('mcorp','mcorp+og') where r7t.id_state=t.id_state) as ctr7,
(select count(*) from towns2011 r8 where r8.tvtype in ('mcorp','mcorp+og') and r8.id_state=t.id_state) as ctr8,
id_state",
vpr.polygons as ctr9,
vpr.villages as ctr10,
t.id_state",
'join' => 'left join `village-polygon-report` vpr on vpr.id_state=t.id_state',
'order' => 'st_name',
'condition' => 'polytype=?',
'params' => [
Expand All @@ -184,7 +194,7 @@ static function repACs()
] );
foreach ( $rs as $r )
{
$data = [
$data = [
$r->st_name,
$r->ctr1,
$r->ctr2,
Expand All @@ -194,16 +204,18 @@ static function repACs()
$r->ctr6,
$r->ctr7,
$r->ctr8,
$r->id_state
$r->ctr9,
$r->ctr10,
$r->id_state
];

$mx = $data [1];
$score = 0;
for($i = 2; $i < 7; $i ++)
{
$score += min ( $data [$i], $mx ) / $mx;
}
$data[] = $score/5;
$data[] = $score/5;
$row [] = $data;
}
return $row;
Expand Down
2 changes: 1 addition & 1 deletion protected/views/site/_assembly.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
] );

?>
<h2 class="acname"><?= CHtml::link(__('{acname} Assembly Constituency - #{acno}',['{acname}' => strtolower($poly->acname),'{acno}' => $data->acno]),['state/assembly','acno' => $data->acno,'id_state' => $poly->id_state])?></h2>
<h2 class="acname"><?= CHtml::link(__('{acname} Assembly Constituency - #{acno}',['{acname}' => strtolower($poly->name),'{acno}' => $data->acno]),['state/assembly','acno' => $data->acno,'id_state' => $poly->id_state])?></h2>

<?php

Expand Down
43 changes: 43 additions & 0 deletions protected/views/site/_village.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/* @var $this SiteController */
/* @var $data Array */
?>

<div class="view ward">
<h2 class="acname"><?=__('{villagename} Village',['{villagename}' => strtolower($data->name)])?></h2>

<?php
if (isset ( $data->village ))
{
$this->widget ( 'zii.widgets.CDetailView',
array (
'data' => $data,
'attributes' => array (
[ // related city displayed as a link
'label' => __ ( 'Village' ),
'value' => function ($data)
{
return $data->village->name;
}
],
[ // related city displayed as a link
'label' => __ ( 'Panchayat' ),
'value' => function ($data)
{
return $data->village->panchayat->name;
}
],
[ // related city displayed as a link
'label' => __ ( 'Block' ),
'value' => function ($data)
{
return $data->village->panchayat->block->name;
}
]

)
) );
}
?>

</div>
19 changes: 15 additions & 4 deletions protected/views/site/placeinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// https://stackoverflow.com/questions/15662910/search-a-table-for-point-in-polygon-using-mysql

$src = [
'condition' => (new CDbExpression ( "ST_Contains(poly, GeomFromText(:point))")) . ' and states.name=:statename',
'with' => ['states'],
'condition' => (new CDbExpression ( "ST_Contains(poly, GeomFromText(:point))")) . ' and state.name=:statename',
'with' => ['state'],
'params' => [
':statename' => $data0[0]->state,
':point' => 'POINT(' . $long . ' ' . $lat . ')'
Expand All @@ -17,9 +17,10 @@
$ass2 = AssemblyPolygon::model ()->findAll ( $src );

$data = [ ];

/* @var $ass AssemblyPolygon */
foreach ( $ass2 as $ass )
{
error_log('GIS-found poly:' . $ass->id_poly . ' name:' . $ass->name . ' type:' . $ass->polytype . ' id_village:' . $ass->id_village);
if ($ass->polytype == 'WARD')
{
$con2 = MunicipalResults::model ()->findByAttributes ( [
Expand All @@ -30,7 +31,7 @@
if ($con2)
$data ['ward'] = $con2;
}
else
else if($ass->polytype == 'AC')
{
$data ['amly_poly'] = $ass;
$con2 = LokSabha2014::model ()->findByAttributes ( [
Expand All @@ -53,6 +54,10 @@
$data ['assembly'] = $con3;
}
}
else if($ass->polytype == 'VILLAGE')
{
$data['village'] = $ass;
}
}

$this->renderPartial ( '_address', [
Expand All @@ -68,6 +73,12 @@
'data0' => $data0,
] );

if (! empty ( $data ['village'] ))
$this->renderPartial ( '_village', [
'data' => $data ['village'],
'data0' => $data0,
] );

if (! empty ( $data ['assembly'] ))
$this->renderPartial ( '_assembly', [
'data' => $data ['assembly'],
Expand Down
90 changes: 52 additions & 38 deletions protected/views/site/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* @var $form CActiveForm */
$this->pageTitle = Yii::app ()->name . ' - ' . __('Data Report');
$this->breadcrumbs = array (
__('Data Report')
__('Data Report')
);
?>

Expand All @@ -23,42 +23,42 @@
'attributes' => array (
0,
1,
2
)
2
)
),
'pagination' => array (
'pageSize' => 50
)
'pageSize' => 50
)
) );

$this->widget ( 'zii.widgets.grid.CGridView',
[
$this->widget ( 'zii.widgets.grid.CGridView',
[
'dataProvider' => $dataProvider,
'template' => '{items}',
'columns' => [
[
'columns' => [
[
'header' => __('City'),
'value' => function ($data)
{
return $data [0];
}
}
],
[
[
'header' => __('Polygons'),
'value' => function ($data)
{
return $data [1];
}
}
],
[
[
'header' => __('Councillors'),
'type' => 'raw',
'value' => function ($data)
{
return $data [2] . ' ' . (empty($data['rti']) ? ' ' : CHtml::link(__('RTI'),$data['rti'],['']));
}
]
]
}
]
]
] );

?>
Expand All @@ -73,7 +73,7 @@
}
tr.score td
{

}
<?php
for($i=1; $i<=20; $i++)
Expand All @@ -84,7 +84,7 @@
b9ackground-size: <?=$i*5?>% 2px;
background-size: <?=$i*5?>% 10%;
}
<?php
<?php
}
?>
</style>
Expand All @@ -99,16 +99,16 @@
'attributes' => array (
0,
1,
2,3,4
)
2,3,4
)
),
'pagination' => array (
'pageSize' => 50
)
'pageSize' => 50
)
) );
$css_master = [];
$this->widget ( 'zii.widgets.grid.CGridView',
[
$this->widget ( 'zii.widgets.grid.CGridView',
[
'template' => '{items}',
'dataProvider' => $dataProvider,
'rowCssClassExpression'=> function($row,$data)
Expand All @@ -123,31 +123,31 @@
//die;
//if(isset($data[$row]))
// echo " - " . print_r($data[$row],true);
//return "score" . intval(100*$data[$row][10]);

//return "score" . intval(100*$data[$row][10]);
},
'columns' => [
[
'columns' => [
[
'header' => __('State'),
'type' => 'raw',
'type' => 'raw',
'value' => function ($data)
{
return CHtml::link($data [0],['state/view','id' => $data[count($data)-1]]);
}
}
],
[
'header' => __('Polygons'),
[
'header' => __('A Poly'),
'value' => function ($data)
{
return $data [1];
}
}
],
[
[
'header' => __('MLAs'),
'value' => function ($data)
{
return $data [2];
}
}
],
[
'header' => __('Phones'),
Expand Down Expand Up @@ -177,13 +177,27 @@
return $data [6];
}
],
[
[
'header' => __ ( 'M Corp' ),
'value' => function ($data)
{
if(!empty($data[8]))
return $data [7] . '/' . $data[8];
}
}
],
[
'header' => __('Villages'),
'value' => function ($data)
{
return $data[10];
}
],
[
'header' => __('V Poly'),
'value' => function ($data)
{
return $data[9];
}
],
/*[
'header' => __('Score'),
Expand All @@ -197,4 +211,4 @@
] );

?>
</div>
</div>

0 comments on commit c154490

Please sign in to comment.