-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
138 lines (101 loc) · 2.72 KB
/
functions.php
File metadata and controls
138 lines (101 loc) · 2.72 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
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
<?php /* Functions for demo*/
/* Update */
function frl_perform_update(){
$task_for_out = frl_get_tasks();
$log_for_out = frl_get_log();
$log_queue = frl_get_log_queue();
$step = count($log_for_out);
if($step > $log_queue){
frl_perform_reset();
return;
}
//add action into log
$new_line = $log_queue[$step];
array_unshift($log_for_out, $new_line);
$file = dirname(__FILE__).'/data/log-out.csv';
$csv_handler = fopen($file,'w');
foreach ($log_for_out as $l) {
fputcsv($csv_handler, $l, ",");
}
fclose($csv_handler);
//change status of task
if($new_line[2] == 'Запрос уточнения'){
//change status to Ждет уточнения
$task_for_out = frl_change_task_status($task_for_out, $new_line[4], 'Ждет уточнения');
}
if($new_line[2] == 'Отклик на задачу'){
//change status to Подтверждено
$task_for_out = frl_change_task_status($task_for_out, $new_line[4], 'Подтверждено');
}
$file = dirname(__FILE__).'/data/tasks-out.csv';
$csv_handler = fopen($file,'w');
foreach ($task_for_out as $t) {
fputcsv($csv_handler, $t, ",");
}
fclose($csv_handler);
}
function frl_perform_reset(){
$path = dirname(__FILE__).'/data/';
copy($path.'log-init.csv', $path.'log-out.csv');
copy($path.'tasks.csv', $path.'tasks-out.csv');
}
function frl_change_task_status($task_for_out, $task_id, $status){
var_dump($task_id);
foreach ($task_for_out as $i => $t) {
if((int)$t[0] === (int)$task_id){
$task_for_out[$i][4] = $status;
break;
}
}
return $task_for_out;
}
/* Display */
function frl_get_tasks(){
$path = dirname(__FILE__).'/data/tasks-out.csv';
$csv = array();
$file = file($path);
foreach ($file as $l) {
$csv[] = str_getcsv($l);
}
return $csv;
}
function frl_get_log(){
$path = dirname(__FILE__).'/data/log-out.csv';
$csv = array();
$file = file($path);
foreach ($file as $l) {
$csv[] = str_getcsv($l);
}
return $csv;
}
function frl_get_log_queue(){
$path = dirname(__FILE__).'/data/log.csv';
$csv = array();
$file = file($path);
foreach ($file as $l) {
$csv[] = str_getcsv($l);
}
return $csv;
}
function frl_get_actions($tasks, $log) {
$actions = array();
return $actions;
}
function frl_count_metrics($tasks, $log){
$metricks = array('open' => 0, 'offers' => 0, 'response' => 0, 'wait' => 0);
foreach ($log as $l) {
if($l[2] == 'Отклик на задачу'){
$metricks['response']++;
}
}
foreach ($tasks as $t) {
if($t[4] == 'Ждет уточнения'){
$metricks['wait']++;
}
if($t[4] != 'Подтверждено'){
$metricks['open']++;
}
}
$metricks['offers'] = ($metricks['open']-2)*3;
return $metricks;
}