gpt4 book ai didi

php - 重构文本以使输入和输出具有一定的时间间隔

转载 作者:行者123 更新时间:2023-12-02 04:25:34 36 4
gpt4 key购买 nike

这是我从生物识别技术中导出的数据,并且以某种方式,其格式为.txt:

UDISKLOG    version=2   date=2019-02-21 firmware=FK254HS30_en_v132
No Mchn EnNo Name Mode IOMd DateTime
000001 1 000000001 ting 268435456 2305 2019/02/16 10:15:56
000002 1 000000001 ting 268435456 2305 2019/02/16 13:45:58
000003 1 000000001 ting 268435456 2305 2019/02/16 13:46:04
000004 1 001500022 julie 268435456 2305 2019/02/16 13:48:52
000005 1 000000001 ting 268435456 2305 2019/02/21 17:33:16
000006 1 000000001 ting 268435456 2305 2019/02/21 18:14:15
000007 1 001500022 julie 268435456 2305 2019/02/21 18:14:55
000008 1 000000002 marielle 268435456 2305 2019/02/21 18:18:15
000009 1 000000001 ting 268435456 2305 2019/02/21 18:52:54
000010 1 000000002 marielle 268435456 2305 2019/02/21 18:53:31
000011 1 000000002 marielle 268435456 2305 2019/02/21 18:55:57
000012 1 000000002 marielle 268435456 2305 2019/02/21 18:56:07
000013 1 001500022 julie 268435456 2305 2019/02/21 20:42:36
000014 1 000000001 ting 268435456 2305 2019/02/21 21:00:23
000015 1 000000001 ting 268435456 2305 2019/02/21 21:02:21
000016 1 000000001 ting 268435456 2305 2019/02/21 21:11:09

通过某种方式,我设法通过以下代码将其转换为仅包含重要细节的数组:
$file = file('GLG_001.txt', FILE_IGNORE_NEW_LINES);
$data = [];

unset($file[0]);
unset($file[1]);

foreach($file as $files){
$explode = explode(' ', $files);

$first_explode = preg_split('/\s+/', $explode[0]);

$data['student_id'][] = $first_explode[2];
$data['time'][] = end($explode);
$explode1 = $explode[count($explode) - 3];
$second_explode = preg_split('/\s+/', $explode1);
$data['date'][] = $second_explode[count($second_explode) - 1];
}

print_r($data);

然后导致:
Array
(
[student_id] => Array
(
[0] => 000000001
[1] => 000000001
[2] => 001500022
[3] => 000000002
[4] => 000000001
[5] => 000000002
[6] => 000000002
[7] => 000000002
[8] => 001500022
[9] => 000000001
[10] => 000000001
[11] => 000000001
)

[time] => Array
(
[0] => 17:33:16
[1] => 18:14:15
[2] => 18:14:55
[3] => 18:18:15
[4] => 18:52:54
[5] => 18:53:31
[6] => 18:55:57
[7] => 18:56:07
[8] => 20:42:36
[9] => 21:00:23
[10] => 21:02:21
[11] => 21:11:09
)

[date] => Array
(
[0] => 2019/02/21
[1] => 2019/02/21
[2] => 2019/02/21
[3] => 2019/02/21
[4] => 2019/02/21
[5] => 2019/02/21
[6] => 2019/02/21
[7] => 2019/02/21
[8] => 2019/02/21
[9] => 2019/02/21
[10] => 2019/02/21
[11] => 2019/02/21
)

)

请注意,数组中有相同的学生ID,即学生输入其生物特征信息到系统中的时间。第一个唯一的ID表示他/她进入,而他/她的最后一个ID表示超时。在给定的数组中,学生ID 000000001在键 [0]中,而他的最后一个ID在键 [11]中。将其与 $data['time']进行比较,他/她的停留时间为 [0] => 17:33:16,他/她的超时时间为 [11] => 21:11:09。确定超时和超时后,我想将其存储到数组中。因此,然后 $data['student_id']将通过 array_unique()转换为具有唯一值的数组,因此,也将时间输入和超时存储到与 count(array_uniqe($data['student_id']))相同计数的数组中。因此,最终输出将是:
Array(
[student_id] => Array
(
[0] => 000000001
[1] => 001500022
[2] => 000000002
)
[time_in] => Array
(
[0] => 17:33:16
[1] => 18:14:55
[2] => 18:18:15
)

[time_out] => Array
(
[0] => 21:11:09
[1] => 20:42:36
[2] => 18:56:07
)
[date] => Array
(
[0] => 2019/02/21
[1] => 2019/02/21
[2] => 2019/02/21
)
)

但是,我不知道该怎么做最后一部分,要花些时间和些时间。

最佳答案

从您的问题中,我了解到您想获得学生的“第一时间”和“最后时间”。

我认为将日期和时间分别放在不同的数组中会比较困难。因此,在将文件读入数组时,最好将时间和日期放在一起。
稍后,您可以轻松分隔日期和时间。

如果我正确地理解了您的问题,看来您只需要找到每个学生的第一时间和最后时间的数组的最小和最大索引。

我在下面写一些代码和结果。希望这会帮助你。

//请注意,我将日期和时间放在一起。

<?php

// Array given
$ar_data['student_id'][0] = '000000001';
$ar_data['student_id'][1] = '000000001';
$ar_data['student_id'][2] = '001500022';
$ar_data['student_id'][3] = '000000002';
$ar_data['student_id'][4] = '000000001';
$ar_data['student_id'][5] = '000000002';
$ar_data['student_id'][6] = '000000002';
$ar_data['student_id'][7] = '000000002';
$ar_data['student_id'][8] = '001500022';
$ar_data['student_id'][9] = '000000001';
$ar_data['student_id'][10] = '000000001';
$ar_data['student_id'][11] = '000000001';

$ar_data['time'][0] = '2019/02/21 17:33:16';
$ar_data['time'][1] = '2019/02/21 18:14:15';
$ar_data['time'][2] = '2019/02/21 18:14:55';
$ar_data['time'][3] = '2019/02/21 18:18:15';
$ar_data['time'][4] = '2019/02/21 18:52:54';
$ar_data['time'][5] = '2019/02/21 18:53:31';
$ar_data['time'][6] = '2019/02/21 18:55:57';
$ar_data['time'][7] = '2019/02/21 18:56:07';
$ar_data['time'][8] = '2019/02/21 20:42:36';
$ar_data['time'][9] = '2019/02/21 21:00:23';
$ar_data['time'][10] = '2019/02/21 21:02:21';
$ar_data['time'][11] = '2019/02/21 21:11:09';


// Restructure
// Get all in and out time
foreach ($ar_data['student_id'] as $index => $value) {
$ar_new[$value][] = $ar_data['time'][$index];
}

// Make a result array
foreach ($ar_new as $student_id => $ar_time_list) {
$ar_result['student_id'][] = $student_id;
$ar_result['time_in'][] = $ar_time_list[0];
$count_time = count($ar_time_list) - 1;
$ar_result['time_out'][] = $ar_time_list[$count_time];
}


echo "\nResult:\n";
print_r($ar_result);

?>

-------------------------------------------------- ----------------------------------
Result:
Array
(
[student_id] => Array
(
[0] => 000000001
[1] => 001500022
[2] => 000000002
)

[time_in] => Array
(
[0] => 2019/02/21 17:33:16
[1] => 2019/02/21 18:14:55
[2] => 2019/02/21 18:18:15
)

[time_out] => Array
(
[0] => 2019/02/21 21:11:09
[1] => 2019/02/21 20:42:36
[2] => 2019/02/21 18:56:07
)

)

关于php - 重构文本以使输入和输出具有一定的时间间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54820764/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com