-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.php
More file actions
92 lines (84 loc) · 2.88 KB
/
Matrix.php
File metadata and controls
92 lines (84 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Macocci7\PhpCombination\Combination;
use Macocci7\PhpCsv\Csv;
use Macocci7\PhpScatterplot\Scatterplot;
$cu = new Csv(__DIR__ . '/csv/weather_tokyo_2026mar.csv');
$cb = new Combination();
$cu->encode('SJIS', 'UTF-8')
->offsetRow(7);
$heads = $cu->row(5);
$days = $cu->raw()->column(1);
$dictionary = [
'平均気温(℃)' => 'Mean Temperature(℃)',
'最高気温(℃)' => 'Maximum Temperature(℃)',
'最低気温(℃)' => 'Minimum Temperature(℃)',
'日照時間(時間)' => 'Sunshine Hours(h)',
'降水量の合計(mm)' => 'Precipitation Amount(mm)',
'平均現地気圧(hPa)' => 'Mean Local Air Pressure(hPa)',
];
$columns = [2, 5, 8, 11, 15, 22];
$parsed = [];
$pairs = $cb->pairs($columns);
foreach ($pairs as $index => $pair) {
$x = $pair[0];
$y = $pair[1];
$layers = [
'Tokyo, Japan' => [
'x' => $cu->float()->column($x),
'y' => $cu->float()->column($y),
],
];
$sp = new Scatterplot();
$sp->layers($layers)
->regressionLineOn()
->labelX($dictionary[$heads[$x]])
->labelY($dictionary[$heads[$y]])
->caption('Weather in Tokyo : ' . $days[0] . '~' . $days[count($days) - 1])
->create(sprintf(__DIR__ . "/img/Matrix%02d.png", $index));
$parsed[] = $sp->parse($layers);
}
// Markdown -------------------------------------
echo "# Scatterplot Matrix: Weather in Tokyo\n\n";
echo "## Data Source\n\n"
. "<a href='https://www.data.jma.go.jp/gmd/risk/obsdl/' target='_blank'>"
. "Japan Meteorological Agency</a>\n\n";
echo "## Period: " . $days[0] . '~' . $days[count($days) - 1] . "\n";
$count = count($columns);
echo "<table>\n";
echo "<tr>\n<th>\</th>\n";
foreach ($columns as $column) {
echo "<th>" . $dictionary[$heads[$column]] . "</th>\n";
}
echo "</tr>\n";
$index = 0;
for ($b = 0; $b < $count; $b++) {
echo "<tr><td>" . $dictionary[$heads[$columns[$b]]] . "</td>\n";
for ($a = 0; $a < $count; $a++) {
echo "<td>";
if ($a > $b) {
$imgsrc = 'img/Matrix' . sprintf('%02d', $index) . '.png';
echo '<a href="' . $imgsrc . '">';
echo '<img src="' . $imgsrc . '" width="120">';
echo "</a><br />\n";
echo "<details><summary>Properties</summary>\n\n";
foreach ($parsed[$index]['Tokyo, Japan'] as $key => $property) {
if (is_array($property)) {
echo "- " . $key . ": \n";
foreach ($property as $k => $v) {
echo "\t- " . $k . ": " . $v . "\n";
}
} else {
echo "- " . $key . ": " . $property . "\n";
}
}
echo "</details>";
$index++;
} else {
echo "-";
}
echo "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";