| Conditions | 99 |
| Paths | 120 |
| Total Lines | 505 |
| Code Lines | 389 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 228 | public function postCustomChartAction(ServerRequestInterface $request): ResponseInterface |
||
| 229 | { |
||
| 230 | $tree = Validator::attributes($request)->tree(); |
||
| 231 | |||
| 232 | $statistics = app(Statistics::class); |
||
| 233 | assert($statistics instanceof Statistics); |
||
| 234 | |||
| 235 | $statistics_data = new StatisticsData($tree, new UserService()); |
||
| 236 | |||
| 237 | $x_axis_type = Validator::parsedBody($request)->integer('x-as'); |
||
| 238 | $y_axis_type = Validator::parsedBody($request)->integer('y-as'); |
||
| 239 | $z_axis_type = Validator::parsedBody($request)->integer('z-as'); |
||
| 240 | $ydata = []; |
||
| 241 | |||
| 242 | switch ($x_axis_type) { |
||
| 243 | case self::X_AXIS_INDIVIDUAL_MAP: |
||
| 244 | return response($statistics->chartDistribution( |
||
| 245 | Validator::parsedBody($request)->string('chart_shows'), |
||
| 246 | Validator::parsedBody($request)->string('chart_type'), |
||
| 247 | Validator::parsedBody($request)->string('SURN') |
||
| 248 | )); |
||
| 249 | |||
| 250 | case self::X_AXIS_BIRTH_MAP: |
||
| 251 | return response($statistics->chartDistribution( |
||
| 252 | Validator::parsedBody($request)->string('chart_shows'), |
||
| 253 | 'birth_distribution_chart' |
||
| 254 | )); |
||
| 255 | |||
| 256 | case self::X_AXIS_DEATH_MAP: |
||
| 257 | return response($statistics->chartDistribution( |
||
| 258 | Validator::parsedBody($request)->string('chart_shows'), |
||
| 259 | 'death_distribution_chart' |
||
| 260 | )); |
||
| 261 | |||
| 262 | case self::X_AXIS_MARRIAGE_MAP: |
||
| 263 | return response($statistics->chartDistribution( |
||
| 264 | Validator::parsedBody($request)->string('chart_shows'), |
||
| 265 | 'marriage_distribution_chart' |
||
| 266 | )); |
||
| 267 | |||
| 268 | case self::X_AXIS_BIRTH_MONTH: |
||
| 269 | $chart_title = I18N::translate('Month of birth'); |
||
| 270 | $x_axis_title = I18N::translate('Month'); |
||
| 271 | $x_axis = $this->axisMonths(); |
||
| 272 | |||
| 273 | switch ($y_axis_type) { |
||
| 274 | case self::Y_AXIS_NUMBERS: |
||
| 275 | $y_axis_title = I18N::translate('Individuals'); |
||
| 276 | break; |
||
| 277 | case self::Y_AXIS_PERCENT: |
||
| 278 | $y_axis_title = '%'; |
||
| 279 | break; |
||
| 280 | default: |
||
| 281 | throw new HttpNotFoundException(); |
||
| 282 | } |
||
| 283 | |||
| 284 | switch ($z_axis_type) { |
||
| 285 | case self::Z_AXIS_ALL: |
||
| 286 | $z_axis = $this->axisAll(); |
||
| 287 | $rows = $statistics_data->countEventsByMonth('BIRT', 0, 0); |
||
| 288 | foreach ($rows as $month => $total) { |
||
| 289 | $this->fillYData($month, 0, $total, $x_axis, $z_axis, $ydata); |
||
| 290 | } |
||
| 291 | break; |
||
| 292 | case self::Z_AXIS_SEX: |
||
| 293 | $z_axis = $this->axisSexes(); |
||
| 294 | $rows = $statistics_data->countEventsByMonthAndSex('BIRT', 0, 0); |
||
| 295 | foreach ($rows as $row) { |
||
| 296 | $this->fillYData($row->month, $row->sex, $row->total, $x_axis, $z_axis, $ydata); |
||
| 297 | } |
||
| 298 | break; |
||
| 299 | case self::Z_AXIS_TIME: |
||
| 300 | $boundaries_csv = Validator::parsedBody($request)->string('z-axis-boundaries-periods'); |
||
| 301 | $z_axis = $this->axisYears($boundaries_csv); |
||
| 302 | $prev_boundary = 0; |
||
| 303 | foreach (array_keys($z_axis) as $boundary) { |
||
| 304 | $rows = $statistics_data->countEventsByMonth('BIRT', $prev_boundary, $boundary); |
||
| 305 | foreach ($rows as $month => $total) { |
||
| 306 | $this->fillYData($month, $boundary, $total, $x_axis, $z_axis, $ydata); |
||
| 307 | } |
||
| 308 | $prev_boundary = $boundary + 1; |
||
| 309 | } |
||
| 310 | break; |
||
| 311 | default: |
||
| 312 | throw new HttpNotFoundException(); |
||
| 313 | } |
||
| 314 | |||
| 315 | return response($this->myPlot($chart_title, $x_axis, $x_axis_title, $ydata, $y_axis_title, $z_axis, $y_axis_type)); |
||
| 316 | |||
| 317 | case self::X_AXIS_DEATH_MONTH: |
||
| 318 | $chart_title = I18N::translate('Month of death'); |
||
| 319 | $x_axis_title = I18N::translate('Month'); |
||
| 320 | $x_axis = $this->axisMonths(); |
||
| 321 | |||
| 322 | switch ($y_axis_type) { |
||
| 323 | case self::Y_AXIS_NUMBERS: |
||
| 324 | $y_axis_title = I18N::translate('Individuals'); |
||
| 325 | break; |
||
| 326 | case self::Y_AXIS_PERCENT: |
||
| 327 | $y_axis_title = '%'; |
||
| 328 | break; |
||
| 329 | default: |
||
| 330 | throw new HttpNotFoundException(); |
||
| 331 | } |
||
| 332 | |||
| 333 | switch ($z_axis_type) { |
||
| 334 | case self::Z_AXIS_ALL: |
||
| 335 | $z_axis = $this->axisAll(); |
||
| 336 | $rows = $statistics_data->countEventsByMonth('DEAT', 0, 0); |
||
| 337 | foreach ($rows as $month => $total) { |
||
| 338 | $this->fillYData($month, 0, $total, $x_axis, $z_axis, $ydata); |
||
| 339 | } |
||
| 340 | break; |
||
| 341 | case self::Z_AXIS_SEX: |
||
| 342 | $z_axis = $this->axisSexes(); |
||
| 343 | $rows = $statistics_data->countEventsByMonthAndSex('DEAT', 0, 0); |
||
| 344 | foreach ($rows as $row) { |
||
| 345 | $this->fillYData($row->month, $row->sex, $row->total, $x_axis, $z_axis, $ydata); |
||
| 346 | } |
||
| 347 | break; |
||
| 348 | case self::Z_AXIS_TIME: |
||
| 349 | $boundaries_csv = Validator::parsedBody($request)->string('z-axis-boundaries-periods'); |
||
| 350 | $z_axis = $this->axisYears($boundaries_csv); |
||
| 351 | $prev_boundary = 0; |
||
| 352 | foreach (array_keys($z_axis) as $boundary) { |
||
| 353 | $rows = $statistics_data->countEventsByMonth('DEAT', $prev_boundary, $boundary); |
||
| 354 | foreach ($rows as $month => $total) { |
||
| 355 | $this->fillYData($month, $boundary, $total, $x_axis, $z_axis, $ydata); |
||
| 356 | } |
||
| 357 | $prev_boundary = $boundary + 1; |
||
| 358 | } |
||
| 359 | break; |
||
| 360 | default: |
||
| 361 | throw new HttpNotFoundException(); |
||
| 362 | } |
||
| 363 | |||
| 364 | return response($this->myPlot($chart_title, $x_axis, $x_axis_title, $ydata, $y_axis_title, $z_axis, $y_axis_type)); |
||
| 365 | |||
| 366 | case self::X_AXIS_MARRIAGE_MONTH: |
||
| 367 | $chart_title = I18N::translate('Month of marriage'); |
||
| 368 | $x_axis_title = I18N::translate('Month'); |
||
| 369 | $x_axis = $this->axisMonths(); |
||
| 370 | |||
| 371 | switch ($y_axis_type) { |
||
| 372 | case self::Y_AXIS_NUMBERS: |
||
| 373 | $y_axis_title = I18N::translate('Families'); |
||
| 374 | break; |
||
| 375 | case self::Y_AXIS_PERCENT: |
||
| 376 | $y_axis_title = '%'; |
||
| 377 | break; |
||
| 378 | default: |
||
| 379 | throw new HttpNotFoundException(); |
||
| 380 | } |
||
| 381 | |||
| 382 | switch ($z_axis_type) { |
||
| 383 | case self::Z_AXIS_ALL: |
||
| 384 | $z_axis = $this->axisAll(); |
||
| 385 | $rows = $statistics_data->countEventsByMonth('MARR', 0, 0); |
||
| 386 | foreach ($rows as $month => $total) { |
||
| 387 | $this->fillYData($month, 0, $total, $x_axis, $z_axis, $ydata); |
||
| 388 | } |
||
| 389 | break; |
||
| 390 | case self::Z_AXIS_TIME: |
||
| 391 | $boundaries_csv = Validator::parsedBody($request)->string('z-axis-boundaries-periods'); |
||
| 392 | $z_axis = $this->axisYears($boundaries_csv); |
||
| 393 | $prev_boundary = 0; |
||
| 394 | foreach (array_keys($z_axis) as $boundary) { |
||
| 395 | $rows = $statistics_data->countEventsByMonth('MARR', $prev_boundary, $boundary); |
||
| 396 | foreach ($rows as $month => $total) { |
||
| 397 | $this->fillYData($month, $boundary, $total, $x_axis, $z_axis, $ydata); |
||
| 398 | } |
||
| 399 | $prev_boundary = $boundary + 1; |
||
| 400 | } |
||
| 401 | break; |
||
| 402 | default: |
||
| 403 | throw new HttpNotFoundException(); |
||
| 404 | } |
||
| 405 | |||
| 406 | return response($this->myPlot($chart_title, $x_axis, $x_axis_title, $ydata, $y_axis_title, $z_axis, $y_axis_type)); |
||
| 407 | |||
| 408 | case self::X_AXIS_FIRST_CHILD_MONTH: |
||
| 409 | $chart_title = I18N::translate('Month of birth of first child in a relation'); |
||
| 410 | $x_axis_title = I18N::translate('Month'); |
||
| 411 | $x_axis = $this->axisMonths(); |
||
| 412 | |||
| 413 | switch ($y_axis_type) { |
||
| 414 | case self::Y_AXIS_NUMBERS: |
||
| 415 | $y_axis_title = I18N::translate('Children'); |
||
| 416 | break; |
||
| 417 | case self::Y_AXIS_PERCENT: |
||
| 418 | $y_axis_title = '%'; |
||
| 419 | break; |
||
| 420 | default: |
||
| 421 | throw new HttpNotFoundException(); |
||
| 422 | } |
||
| 423 | |||
| 424 | switch ($z_axis_type) { |
||
| 425 | case self::Z_AXIS_ALL: |
||
| 426 | $z_axis = $this->axisAll(); |
||
| 427 | $rows = $statistics_data->countFirstChildrenByMonth(0, 0); |
||
| 428 | foreach ($rows as $month => $total) { |
||
| 429 | $this->fillYData($month, 0, $total, $x_axis, $z_axis, $ydata); |
||
| 430 | } |
||
| 431 | break; |
||
| 432 | case self::Z_AXIS_SEX: |
||
| 433 | $z_axis = $this->axisSexes(); |
||
| 434 | $rows = $statistics_data->countFirstChildrenByMonthAndSex(0, 0); |
||
| 435 | foreach ($rows as $row) { |
||
| 436 | $this->fillYData($row->month, $row->sex, $row->total, $x_axis, $z_axis, $ydata); |
||
| 437 | } |
||
| 438 | break; |
||
| 439 | case self::Z_AXIS_TIME: |
||
| 440 | $boundaries_csv = Validator::parsedBody($request)->string('z-axis-boundaries-periods'); |
||
| 441 | $z_axis = $this->axisYears($boundaries_csv); |
||
| 442 | $prev_boundary = 0; |
||
| 443 | foreach (array_keys($z_axis) as $boundary) { |
||
| 444 | $rows = $statistics_data->countFirstChildrenByMonth($prev_boundary, $boundary); |
||
| 445 | foreach ($rows as $month => $total) { |
||
| 446 | $this->fillYData($month, $boundary, $total, $x_axis, $z_axis, $ydata); |
||
| 447 | } |
||
| 448 | $prev_boundary = $boundary + 1; |
||
| 449 | } |
||
| 450 | break; |
||
| 451 | default: |
||
| 452 | throw new HttpNotFoundException(); |
||
| 453 | } |
||
| 454 | |||
| 455 | return response($this->myPlot($chart_title, $x_axis, $x_axis_title, $ydata, $y_axis_title, $z_axis, $y_axis_type)); |
||
| 456 | |||
| 457 | case self::X_AXIS_FIRST_MARRIAGE_MONTH: |
||
| 458 | $chart_title = I18N::translate('Month of first marriage'); |
||
| 459 | $x_axis_title = I18N::translate('Month'); |
||
| 460 | $x_axis = $this->axisMonths(); |
||
| 461 | |||
| 462 | switch ($y_axis_type) { |
||
| 463 | case self::Y_AXIS_NUMBERS: |
||
| 464 | $y_axis_title = I18N::translate('Families'); |
||
| 465 | break; |
||
| 466 | case self::Y_AXIS_PERCENT: |
||
| 467 | $y_axis_title = '%'; |
||
| 468 | break; |
||
| 469 | default: |
||
| 470 | throw new HttpNotFoundException(); |
||
| 471 | } |
||
| 472 | |||
| 473 | switch ($z_axis_type) { |
||
| 474 | case self::Z_AXIS_ALL: |
||
| 475 | $z_axis = $this->axisAll(); |
||
| 476 | $rows = $statistics_data->countFirstMarriagesByMonth($tree, 0, 0); |
||
| 477 | foreach ($rows as $month => $total) { |
||
| 478 | $this->fillYData($month, 0, $total, $x_axis, $z_axis, $ydata); |
||
| 479 | } |
||
| 480 | break; |
||
| 481 | case self::Z_AXIS_TIME: |
||
| 482 | $boundaries_csv = Validator::parsedBody($request)->string('z-axis-boundaries-periods'); |
||
| 483 | $z_axis = $this->axisYears($boundaries_csv); |
||
| 484 | $prev_boundary = 0; |
||
| 485 | foreach (array_keys($z_axis) as $boundary) { |
||
| 486 | $rows = $statistics_data->countFirstMarriagesByMonth($tree, $prev_boundary, $boundary); |
||
| 487 | foreach ($rows as $month => $total) { |
||
| 488 | $this->fillYData($month, 0, $total, $x_axis, $z_axis, $ydata); |
||
| 489 | } |
||
| 490 | $prev_boundary = $boundary + 1; |
||
| 491 | } |
||
| 492 | break; |
||
| 493 | default: |
||
| 494 | throw new HttpNotFoundException(); |
||
| 495 | } |
||
| 496 | |||
| 497 | return response($this->myPlot($chart_title, $x_axis, $x_axis_title, $ydata, $y_axis_title, $z_axis, $y_axis_type)); |
||
| 498 | |||
| 499 | case self::X_AXIS_AGE_AT_DEATH: |
||
| 500 | $chart_title = I18N::translate('Average age at death'); |
||
| 501 | $x_axis_title = I18N::translate('age'); |
||
| 502 | $boundaries_csv = Validator::parsedBody($request)->string('x-axis-boundaries-ages'); |
||
| 503 | $x_axis = $this->axisNumbers($boundaries_csv); |
||
| 504 | |||
| 505 | switch ($y_axis_type) { |
||
| 506 | case self::Y_AXIS_NUMBERS: |
||
| 507 | $y_axis_title = I18N::translate('Individuals'); |
||
| 508 | break; |
||
| 509 | case self::Y_AXIS_PERCENT: |
||
| 510 | $y_axis_title = '%'; |
||
| 511 | break; |
||
| 512 | default: |
||
| 513 | throw new HttpNotFoundException(); |
||
| 514 | } |
||
| 515 | |||
| 516 | switch ($z_axis_type) { |
||
| 517 | case self::Z_AXIS_ALL: |
||
| 518 | $z_axis = $this->axisAll(); |
||
| 519 | $rows = $statistics_data->statsAgeQuery('ALL', 0, 0); |
||
| 520 | foreach ($rows as $row) { |
||
| 521 | $years = (int) ($row->days / self::DAYS_IN_YEAR); |
||
| 522 | $this->fillYData($years, 0, 1, $x_axis, $z_axis, $ydata); |
||
| 523 | } |
||
| 524 | break; |
||
| 525 | case self::Z_AXIS_SEX: |
||
| 526 | $z_axis = $this->axisSexes(); |
||
| 527 | foreach (array_keys($z_axis) as $sex) { |
||
| 528 | $rows = $statistics_data->statsAgeQuery($sex, 0, 0); |
||
| 529 | foreach ($rows as $row) { |
||
| 530 | $years = (int) ($row->days / self::DAYS_IN_YEAR); |
||
| 531 | $this->fillYData($years, $sex, 1, $x_axis, $z_axis, $ydata); |
||
| 532 | } |
||
| 533 | } |
||
| 534 | break; |
||
| 535 | case self::Z_AXIS_TIME: |
||
| 536 | $boundaries_csv = Validator::parsedBody($request)->string('z-axis-boundaries-periods'); |
||
| 537 | $z_axis = $this->axisYears($boundaries_csv); |
||
| 538 | $prev_boundary = 0; |
||
| 539 | foreach (array_keys($z_axis) as $boundary) { |
||
| 540 | $rows = $statistics_data->statsAgeQuery('ALL', $prev_boundary, $boundary); |
||
| 541 | foreach ($rows as $row) { |
||
| 542 | $years = (int) ($row->days / self::DAYS_IN_YEAR); |
||
| 543 | $this->fillYData($years, $boundary, 1, $x_axis, $z_axis, $ydata); |
||
| 544 | } |
||
| 545 | $prev_boundary = $boundary + 1; |
||
| 546 | } |
||
| 547 | |||
| 548 | break; |
||
| 549 | default: |
||
| 550 | throw new HttpNotFoundException(); |
||
| 551 | } |
||
| 552 | |||
| 553 | return response($this->myPlot($chart_title, $x_axis, $x_axis_title, $ydata, $y_axis_title, $z_axis, $y_axis_type)); |
||
| 554 | |||
| 555 | case self::X_AXIS_AGE_AT_MARRIAGE: |
||
| 556 | $chart_title = I18N::translate('Age in year of marriage'); |
||
| 557 | $x_axis_title = I18N::translate('age'); |
||
| 558 | $boundaries_csv = Validator::parsedBody($request)->string('x-axis-boundaries-ages_m'); |
||
| 559 | $x_axis = $this->axisNumbers($boundaries_csv); |
||
| 560 | |||
| 561 | switch ($y_axis_type) { |
||
| 562 | case self::Y_AXIS_NUMBERS: |
||
| 563 | $y_axis_title = I18N::translate('Individuals'); |
||
| 564 | break; |
||
| 565 | case self::Y_AXIS_PERCENT: |
||
| 566 | $y_axis_title = '%'; |
||
| 567 | break; |
||
| 568 | default: |
||
| 569 | throw new HttpNotFoundException(); |
||
| 570 | } |
||
| 571 | |||
| 572 | switch ($z_axis_type) { |
||
| 573 | case self::Z_AXIS_ALL: |
||
| 574 | $z_axis = $this->axisAll(); |
||
| 575 | // The stats query doesn't have an "all" function, so query M/F separately |
||
| 576 | foreach (['M', 'F'] as $sex) { |
||
| 577 | $rows = $statistics->statsMarrAgeQuery($sex); |
||
| 578 | foreach ($rows as $row) { |
||
| 579 | $years = (int) ($row->age / self::DAYS_IN_YEAR); |
||
| 580 | $this->fillYData($years, 0, 1, $x_axis, $z_axis, $ydata); |
||
| 581 | } |
||
| 582 | } |
||
| 583 | break; |
||
| 584 | case self::Z_AXIS_SEX: |
||
| 585 | $z_axis = $this->axisSexes(); |
||
| 586 | foreach (array_keys($z_axis) as $sex) { |
||
| 587 | $rows = $statistics->statsMarrAgeQuery($sex); |
||
| 588 | foreach ($rows as $row) { |
||
| 589 | $years = (int) ($row->age / self::DAYS_IN_YEAR); |
||
| 590 | $this->fillYData($years, $sex, 1, $x_axis, $z_axis, $ydata); |
||
| 591 | } |
||
| 592 | } |
||
| 593 | break; |
||
| 594 | case self::Z_AXIS_TIME: |
||
| 595 | $boundaries_csv = Validator::parsedBody($request)->string('z-axis-boundaries-periods'); |
||
| 596 | $z_axis = $this->axisYears($boundaries_csv); |
||
| 597 | // The stats query doesn't have an "all" function, so query M/F separately |
||
| 598 | foreach (['M', 'F'] as $sex) { |
||
| 599 | $prev_boundary = 0; |
||
| 600 | foreach (array_keys($z_axis) as $boundary) { |
||
| 601 | $rows = $statistics->statsMarrAgeQuery($sex, $prev_boundary, $boundary); |
||
| 602 | foreach ($rows as $row) { |
||
| 603 | $years = (int) ($row->age / self::DAYS_IN_YEAR); |
||
| 604 | $this->fillYData($years, $boundary, 1, $x_axis, $z_axis, $ydata); |
||
| 605 | } |
||
| 606 | $prev_boundary = $boundary + 1; |
||
| 607 | } |
||
| 608 | } |
||
| 609 | break; |
||
| 610 | default: |
||
| 611 | throw new HttpNotFoundException(); |
||
| 612 | } |
||
| 613 | |||
| 614 | return response($this->myPlot($chart_title, $x_axis, $x_axis_title, $ydata, $y_axis_title, $z_axis, $y_axis_type)); |
||
| 615 | |||
| 616 | case self::X_AXIS_AGE_AT_FIRST_MARRIAGE: |
||
| 617 | $chart_title = I18N::translate('Age in year of first marriage'); |
||
| 618 | $x_axis_title = I18N::translate('age'); |
||
| 619 | $boundaries_csv = Validator::parsedBody($request)->string('x-axis-boundaries-ages_m'); |
||
| 620 | $x_axis = $this->axisNumbers($boundaries_csv); |
||
| 621 | |||
| 622 | switch ($y_axis_type) { |
||
| 623 | case self::Y_AXIS_NUMBERS: |
||
| 624 | $y_axis_title = I18N::translate('Individuals'); |
||
| 625 | break; |
||
| 626 | case self::Y_AXIS_PERCENT: |
||
| 627 | $y_axis_title = '%'; |
||
| 628 | break; |
||
| 629 | default: |
||
| 630 | throw new HttpNotFoundException(); |
||
| 631 | } |
||
| 632 | |||
| 633 | switch ($z_axis_type) { |
||
| 634 | case self::Z_AXIS_ALL: |
||
| 635 | $z_axis = $this->axisAll(); |
||
| 636 | // The stats query doesn't have an "all" function, so query M/F separately |
||
| 637 | foreach (['M', 'F'] as $sex) { |
||
| 638 | $rows = $statistics->statsMarrAgeQuery($sex); |
||
| 639 | $indi = []; |
||
| 640 | foreach ($rows as $row) { |
||
| 641 | if (!in_array($row->d_gid, $indi, true)) { |
||
| 642 | $years = (int) ($row->age / self::DAYS_IN_YEAR); |
||
| 643 | $this->fillYData($years, 0, 1, $x_axis, $z_axis, $ydata); |
||
| 644 | $indi[] = $row->d_gid; |
||
| 645 | } |
||
| 646 | } |
||
| 647 | } |
||
| 648 | break; |
||
| 649 | case self::Z_AXIS_SEX: |
||
| 650 | $z_axis = $this->axisSexes(); |
||
| 651 | foreach (array_keys($z_axis) as $sex) { |
||
| 652 | $rows = $statistics->statsMarrAgeQuery($sex); |
||
| 653 | $indi = []; |
||
| 654 | foreach ($rows as $row) { |
||
| 655 | if (!in_array($row->d_gid, $indi, true)) { |
||
| 656 | $years = (int) ($row->age / self::DAYS_IN_YEAR); |
||
| 657 | $this->fillYData($years, $sex, 1, $x_axis, $z_axis, $ydata); |
||
| 658 | $indi[] = $row->d_gid; |
||
| 659 | } |
||
| 660 | } |
||
| 661 | } |
||
| 662 | break; |
||
| 663 | case self::Z_AXIS_TIME: |
||
| 664 | $boundaries_csv = Validator::parsedBody($request)->string('z-axis-boundaries-periods'); |
||
| 665 | $z_axis = $this->axisYears($boundaries_csv); |
||
| 666 | // The stats query doesn't have an "all" function, so query M/F separately |
||
| 667 | foreach (['M', 'F'] as $sex) { |
||
| 668 | $prev_boundary = 0; |
||
| 669 | $indi = []; |
||
| 670 | foreach (array_keys($z_axis) as $boundary) { |
||
| 671 | $rows = $statistics->statsMarrAgeQuery($sex, $prev_boundary, $boundary); |
||
| 672 | foreach ($rows as $row) { |
||
| 673 | if (!in_array($row->d_gid, $indi, true)) { |
||
| 674 | $years = (int) ($row->age / self::DAYS_IN_YEAR); |
||
| 675 | $this->fillYData($years, $boundary, 1, $x_axis, $z_axis, $ydata); |
||
| 676 | $indi[] = $row->d_gid; |
||
| 677 | } |
||
| 678 | } |
||
| 679 | $prev_boundary = $boundary + 1; |
||
| 680 | } |
||
| 681 | } |
||
| 682 | break; |
||
| 683 | default: |
||
| 684 | throw new HttpNotFoundException(); |
||
| 685 | } |
||
| 686 | |||
| 687 | return response($this->myPlot($chart_title, $x_axis, $x_axis_title, $ydata, $y_axis_title, $z_axis, $y_axis_type)); |
||
| 688 | |||
| 689 | case self::X_AXIS_NUMBER_OF_CHILDREN: |
||
| 690 | $chart_title = I18N::translate('Number of children'); |
||
| 691 | $x_axis_title = I18N::translate('Children'); |
||
| 692 | $x_axis = $this->axisNumbers('0,1,2,3,4,5,6,7,8,9,10'); |
||
| 693 | |||
| 694 | switch ($y_axis_type) { |
||
| 695 | case self::Y_AXIS_NUMBERS: |
||
| 696 | $y_axis_title = I18N::translate('Families'); |
||
| 697 | break; |
||
| 698 | case self::Y_AXIS_PERCENT: |
||
| 699 | $y_axis_title = '%'; |
||
| 700 | break; |
||
| 701 | default: |
||
| 702 | throw new HttpNotFoundException(); |
||
| 703 | } |
||
| 704 | |||
| 705 | switch ($z_axis_type) { |
||
| 706 | case self::Z_AXIS_ALL: |
||
| 707 | $z_axis = $this->axisAll(); |
||
| 708 | $rows = $statistics->statsChildrenQuery(); |
||
| 709 | foreach ($rows as $row) { |
||
| 710 | $this->fillYData($row->f_numchil, 0, $row->total, $x_axis, $z_axis, $ydata); |
||
| 711 | } |
||
| 712 | break; |
||
| 713 | case self::Z_AXIS_TIME: |
||
| 714 | $boundaries_csv = Validator::parsedBody($request)->string('z-axis-boundaries-periods'); |
||
| 715 | $z_axis = $this->axisYears($boundaries_csv); |
||
| 716 | $prev_boundary = 0; |
||
| 717 | foreach (array_keys($z_axis) as $boundary) { |
||
| 718 | $rows = $statistics->statsChildrenQuery($prev_boundary, $boundary); |
||
| 719 | foreach ($rows as $row) { |
||
| 720 | $this->fillYData($row->f_numchil, $boundary, $row->total, $x_axis, $z_axis, $ydata); |
||
| 721 | } |
||
| 722 | $prev_boundary = $boundary + 1; |
||
| 723 | } |
||
| 724 | break; |
||
| 725 | default: |
||
| 726 | throw new HttpNotFoundException(); |
||
| 727 | } |
||
| 728 | |||
| 729 | return response($this->myPlot($chart_title, $x_axis, $x_axis_title, $ydata, $y_axis_title, $z_axis, $y_axis_type)); |
||
| 730 | |||
| 731 | default: |
||
| 732 | throw new HttpNotFoundException(); |
||
| 733 | } |
||
| 985 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.