【发布时间】:2020-06-05 15:40:42
【问题描述】:
我有一台装有 Debian 10、Apache/2.4.38、MySQLi、mongodb 和 Php 的服务器。服务器正在运行一个自定义 PHP 程序,该程序允许用户上传他们的测量结果(在 .csv 文件中),然后将其存储在 mongodb 中。
上传的 .csv 文件必须符合预定格式才能上传,如下所示:
Timestamp,Measurement 1,Measurement 2,(etc)
05/06/20 00:15,201,1
05/06/20 00:30,305,4
05/06/20 00:45,400,65
.
.
(continues for the entire duration of the day/week/year)
时间戳必须准确地每 15 分钟设置一次。负责此检查的代码是:
//check time interval
if (isset($document['timestamp']) && $time_step==false && $fileLine>1){
if ($interval>900){
$time_step=true;
$condition_violated=True;
$conditions_errors.="line ".$fileLine. " warning: The ".$key[$i]." condition is violated. \r\n";
file_put_contents($file_name,"line ".$fileLine. " error: One or more time instants are missing in the file you try to upload. Please check the consistency of the measurements in the file. \r\n",FILE_APPEND);
}
}
除了每年有一个非常具体的日期和时间外,这很好用。 尝试上传从 22/02/19 00:15 开始到 31/12/19 23:45 结束的文件时,出现错误:
line 23724 error: One or more time instants are missing in the file you try to upload. Please check the consistency of the measurements in the file.
上面一行是日期:27/10/19 02:45 如果我将文件拆分为两个不同的 .csv 文件,第一个带有 1-23723 行,第二个带有 23725-end 行,基本上跳过了 23724-date 27/10/19 02:45 行,文件仅上传很好。
如果我尝试仅使用以下三个时间步上传文件:
Timestamp,Measurement 1,Measurement 2,(etc)
27/10/19 02:30,0,0
27/10/19 02:45,0,0
27/10/19 03:00,0,0
我得到同样的错误。 整个 2020 年的 25/10/20 02:45 出现相同的问题。 尝试了许多 .csv 文件,同样的错误。
我试图了解操作系统、PHP 代码或数据库 (mongodb) 是否有问题。 有什么建议吗?
第一次编辑
@Buzz 检查间隔的代码应该在这里:
for($i=0; $i < $numofcols; $i++){
$key[$i] =remove_utf8_bom($key[$i]) ;
$min_max_violated=False;
if ($key[$i] == "Timestamp"){
if(strlen($value[$i]) != 14){
$date_time_error=true;
$dt=0;
file_put_contents($file_name,"line ".$fileLine. " error: Date-Time format error.\r\n",FILE_APPEND);
}else{
$document['timestamp'] = $value[$i];
if ($fileLine == 1){
$timestamp_to_cmp=DateTime::createFromFormat('d/m/y H:i',$document['timestamp'])->getTimestamp();
$dt=$timestamp_to_cmp;
}
else{
$dt = DateTime::createFromFormat('d/m/y H:i',$document['timestamp'])->getTimestamp();
$interval=$dt-$timestamp_to_cmp;
/* echo json_encode(["dd"=>$interval]);
exit(); */
}
}
Mongodb 出现在不同的 .php 文件中,我认为错误在此文件中。
【问题讨论】:
-
mongodb 出现在哪里?看起来这发生在检查间隔的代码中,这意味着我们必须查看
interval = newdate - priordate -
@BuzzMoschetti 您好,感谢您抽出宝贵时间。我编辑了我的原始帖子并添加了您要求的代码。有什么帮助吗?其余列有 13 项额外检查,我只发布了关于时间戳的一项。
标签: php database mongodb csv debian