This repository has been archived by the owner on Sep 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate
199 lines (169 loc) · 6.18 KB
/
generate
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env php
<?php
require_once './vendor/autoload.php';
use Balsama\DrupalOrgProject\Stats;
use PHPHtmlParser\Dom;
class rowData {
private $d7_percentage;
private $d8_percentage;
private $note;
private $status;
private $d7_rank;
private $human_readable_name;
private $project;
private function fetchProjectExtra() {
$extra = yaml_parse_file('extra.yml');
$project = $this->project->getMachineName();
if (in_array($project, $extra['core'])) {
$this->setD8Percentage('in core');
$this->setStatus('in core');
}
if (isset($extra['notes'][$project])) {
$this->setNote($extra['notes'][$project]);
if ($this->getStatus() != 'in core') {
$this->setStatus('Deprecated/replaced/other');
}
}
}
public function __construct(Stats $project, $total_d7, $total_d8, $rank) {
$d7_percentage = round((float)($project->getCurrentD7Usage() / $total_d7) * 100) . '%';
$this->setD7Percentage($d7_percentage);
$d8_percentage = round((float)($project->getCurrentD8Usage() / $total_d8) * 100) . '%';
$this->setD8Percentage($d8_percentage);
$this->setNote('');
$status = $project->getD8Stability();
$this->setStatus($status);
$this->d7_rank = $rank;
$human_readable_name = $project->getHumanReadableName();
$this->setHumanReadableName($human_readable_name);
$this->project = $project;
$this->fetchProjectExtra();
}
private function setD7Percentage($d7_percentage) {
$this->d7_percentage = $d7_percentage;
}
private function setD8Percentage($d8_percentage) {
$this->d8_percentage = $d8_percentage;
}
private function setNote($note = '') {
$this->note = $note;
}
private function setStatus($status) {
$this->status = $status;
}
private function setHumanReadableName($human_readable_name) {
$this->human_readable_name = $human_readable_name;
}
public function getD7Percentage() {
return $this->d7_percentage;
}
public function getD8Percentage() {
return $this->d8_percentage;
}
public function getNote() {
return $this->note;
}
public function getStatus() {
return $this->status;
}
public function getHumanReadableName() {
return '[' . $this->human_readable_name . '](https://drupal.org/project/' . $this->project->getMachineName() . ')';
}
public function getD7Rank() {
return $this->d7_rank;
}
public function getAll() {
return [
'rank' => $this->getD7Rank(),
'module' => $this->getHumanReadableName(),
'd8_status' => $this->getStatus(),
'd7_usage' => $this->getD7Percentage(),
'd8_usage' => $this->getD8Percentage(),
'note' => $this->getNote(),
];
}
}
class topProjectList {
private $projects;
private function setProjects($projects) {
$this->projects = $projects;
}
private function fetchProjects($length) {
$pages = round($length / 25);
$modules = [];
for ($i = 0; $i < $pages; $i++) {
$modules_dom = new Dom;
$modules_dom->loadFromUrl('https://www.drupal.org/project/project_module?page=' . $i . '&f[0]=&f[1]=&f[2]=&f[3]=drupal_core%3A103&f[4]=sm_field_project_type%3A%5B%2A%20TO%20%2A%5D&text=&solrsort=iss_project_release_usage%20desc&op=Search');
for ($i2 = 0; $i2 < 25; $i2++) {
$href = $modules_dom->find('.node-project-module h2 a', $i2)->getAttribute('href');
$href_parts = explode('/', $href);
$machine_name = end($href_parts);
$modules[] = $machine_name;
}
}
return $modules;
}
public function getProjects() {
return $this->projects;
}
public function __construct($length) {
$projects = $this->fetchProjects($length);
$this->setProjects($projects);
}
}
class stabilityTotals {
private $stability_totals;
public function __construct() {
$this->stability_totals =[];
}
public function incrementStabilityTotals($stability) {
$this->stability_totals[$stability] = (isset($this->stability_totals[$stability]) ? $this->stability_totals[$stability]:0);
$this->stability_totals[$stability]++;
}
public function getStabilityTotals() {
return $this->stability_totals;
}
}
function md_table_row($row_data) {
return '|' . implode('|', $row_data) . '|';
}
$stability_totals = new stabilityTotals();
$stability_tables = [];
$top_n = 200;
$top_projects = new topProjectList($top_n);
$modules = $top_projects->getProjects();
$core = new Stats('drupal');
$rank = 1;
$main_table_rows = [];
foreach ($modules as $module) {
echo $rank . '. Fetching data for: ' . $module . "\n";
$module_stats = new Stats($module);
$row_data = new rowData($module_stats, $core->getCurrentD7Usage(), $core->getCurrentD8Usage(), $rank);
$main_table_rows[] = md_table_row($row_data->getAll());
$stability_totals->incrementStabilityTotals($row_data->getStatus());
if (in_array($rank, [25, 50, 100, 200])) {
$stability_tables[$rank] = $stability_totals->getStabilityTotals();
}
$rank++;
}
$summary_table_rows = [];
foreach ($stability_tables as $top_n => $totals) {
foreach ($totals as $value => $total) {
$summary_table_rows[$top_n][] = md_table_row([$value, $total, round(($total / $top_n) * 100) . '%']);
}
}
array_unshift($main_table_rows, '|D7 Rank|Module|D8 Status|D7 Usage|D8 Usage|Notes|', '| ------ | ------ | ------ | ------ | ------ | ------ |');
$main_table = implode("\n", $main_table_rows);
$doc[] = '# Current D8 status of the top ' . $top_n . ' Drupal modules';
$doc[] = '';
$doc[] = '#### Last updated: ' . date('d F Y');
$doc[] = '';
$doc[] = $main_table;
$doc[] = '';
foreach ($summary_table_rows as $top_n => $top_n_rows) {
array_unshift($top_n_rows, '|SUMMARY - Top ' . $top_n . '|||', '| ------ | ------:| ------:|');
$doc[] = '';
$doc[] = implode("\n", $top_n_rows);
$doc[] = '';
}
file_put_contents('README.md', implode("\n", $doc));