Collection {#375 ▼
#items: array:3 [▼
2017 => Collection {#372 ▼
#items: array:2 [▼
"ноябрь" => array:2 [▼
"start" => "2017-11-01 00:00:00"
"end" => "2017-11-30 23:59:59"
]
"декабрь" => array:2 [▼
"start" => "2017-12-01 00:00:00"
"end" => "2017-12-31 23:59:59"
]
]
}
2018 => Collection {#373 ▶}
2019 => Collection {#374 ▶}
]
}
Collection {#370 ▼
#items: array:17 [▼
0 => array:1 [▼
2017 => array:1 [▼
"ноябрь" => array:2 [▼
"start" => "2017-11-01 00:00:00"
"end" => "2017-11-30 23:59:59"
]
]
]
1 => array:1 [▼
2017 => array:1 [▼
"декабрь" => array:2 [▼
"start" => "2017-12-01 00:00:00"
"end" => "2017-12-31 23:59:59"
]
]
]
2 => array:1 [▼
2018 => array:1 [▼
"январь" => array:2 [▶]
]
]
3 => array:1 [▼
2018 => array:1 [▼
"февраль" => array:2 [▶]
]
]
4 => array:1 [▶]
5 => array:1 [▶]
6 => array:1 [▶]
7 => array:1 [▶]
8 => array:1 [▶]
9 => array:1 [▶]
10 => array:1 [▶]
11 => array:1 [▶]
12 => array:1 [▶]<code lang="php">
</code>
13 => array:1 [▶]
14 => array:1 [▶]
15 => array:1 [▶]
16 => array:1 [▶]
]
}
->mapToGroups(function($item,$key) {;
return $item[key($item)] = $item;
});
Collection {#375 ▼
#items: array:3 [▼
2017 => Collection {#372 ▼
#items: array:2 [▼
0 => array:1 [▼
"ноябрь" => array:2 [▼
"start" => "2017-11-01 00:00:00"
"end" => "2017-11-30 23:59:59"
]
]
1 => array:1 [▼
"декабрь" => array:2 [▼
"start" => "2017-12-01 00:00:00"
"end" => "2017-12-31 23:59:59"
]
]
]
}
2018 => Collection {#373 ▶}
2019 => Collection {#374 ▶}
]
}
$percents = $percents->map(function($item,$key) {
return $item->{$key} = array($item->city_id => array($item->value => array('start' => $item->from_date, 'end' => $item->to_date)));
});
Collection {#325 ▼
#items: array:7 [▼
0 => array:1 [▼
4 => array:1 [▼
90 => array:2 [▼
"start" => "2017-11-01 00:00:00"
"end" => "2018-11-30 23:59:59"
]
]
]
1 => array:1 [▶]
2 => array:1 [▶]
3 => array:1 [▶]
4 => array:1 [▶]
5 => array:1 [▶]
6 => array:1 [▶]
]
}
немного не тот, что ожидался. moment()
будет каждый раз создать не идентичную дату, разве что делать так:const timestamp = moment.now();
dt = (() => moment(timestamp))();
var snmp = require('net-snmp');
var mysql = require('mysql');
var config = require('./config.json');
var connection = mysql.createConnection(config.mysql_read);
const options = config.options;
const community = config.community;
const oids = config.oids;
async function getSessionsList() {
var sessions = [];
return new Promise((resolve,reject) => {
connection.query('select `device_ip` from `setup_devices` where `is_enabled` = 1;', (err, data) => {
if(err) reject(err);
data.forEach(item =>
sessions.push(new snmp.createSession(item.device_ip,community,options)));
resolve(sessions);
});
});
}
async function getTypes(sessions) {
let types = [];
for (let session of sessions) {
types.push((() => {
return new Promise(resolve => {
session.get([oids.info], (err,res) => {
if(err) throw new Error(err);
resolve(res);
});
});
})());
}
return Promise.all(types);
}
(async () => {
let list = await getSessionsList();
let types = await getTypes(list);
console.log(types);//Result
})();
Promise.all()
try{}catch(){}
? async function getData() {
return await new Promise((resolve,reject) => {
connection.query('select * from `users` where `is_enabled` = 1;', (error, response) => {
if(error) reject(error);
resolve(response.map(item => item.value));
});
})
}
var = getData().then(data => console.log(data));//array data
var = getData().then(data => var = data);
console.log(var);//Promise { <pending> }
async function getData() {
return await connection.query('select * from `users` where `is_enabled` = 1;')
}
var data = getData();
console.log(data)// Promise { <pending> }