$results = [ '1h' => [ 0 => [ 'isConditionMet' => false, ], 1 => [ 'isConditionMet' => true, ], ], '30m' => [ 0 => [ 'isConditionMet' => false, ], 1 => [ 'isConditionMet' => false, ], 2 => [ 'isConditionMet' => true, ], 3 => [ 'isConditionMet' => false, ], ], ]; this is the result of checking occurrences of an event in 2 hours period of data shown in 2 different timeframes: 1 hour and 30 minutes, since its 2 hours of data, we have 2 items in 1h and 4 based on 30 minutes timeframes. so each item in 1h array corresponds with 2 items in 30m array. the problem in here is that I want to make sure if a condition has happend on a higher timeframe (1h in here), there must be at least one occurrences of that on its shorter timeframe (30m in here), so for the example above, the condition is met on second hour, which corresponds with items of 2 and 3 on it's shorter timeframe, so i know its a match. but there is a catch in here:
number of items in $results are dynamic, it might have 1 item or multiple items.
timeframes are also dynamic, available timeframes are: ['1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '8h', '12h', '1d', '3d', '1w', '1M'];
there might be multiple items of the same timeframe, i mean there might be multiple 1h timeframes in the $results array.
what I have so far:
function findSequentialMatch($results) { // Timeframe to minutes mapping for calculations $timeframeToMinutes = [ '1m' => 1, '3m' => 3, '5m' => 5, '15m' => 15, '30m' => 30, '1h' => 60, '2h' => 120, '4h' => 240, '6h' => 360, '8h' => 480, '12h' => 720, '1d' => 1440, '3d' => 4320, '1w' => 10080, '1M' => 43200 ]; // Extract and sort timeframes from the results based on their duration in descending order $timeframes = array_keys($results); usort($timeframes, function ($a, $b) use ($timeframeToMinutes) { return $timeframeToMinutes[$b] - $timeframeToMinutes[$a]; }); // Validate sequential match for each timeframe against its next shorter timeframe for ($i = 0; $i < count($timeframes) - 1; $i++) { $currentLongerTimeframe = $timeframes[$i]; $currentShorterTimeframe = $timeframes[$i + 1]; $ratio = $timeframeToMinutes[$currentLongerTimeframe] / $timeframeToMinutes[$currentShorterTimeframe]; foreach ($results[$currentLongerTimeframe] as $index => $condition) { if ($condition['isConditionMet']) { $foundMatchInShorterTimeframe = false; $start = $index * $ratio; $end = $start + $ratio - 1; for ($j = $start; $j
$results = [ '1h' => [ 0 => [ 'isConditionMet' => false, ], 1 => [ 'isConditionMet' => true, ], ], '30m' => [ 0 => [ 'isConditionMet' => false, ], 1 => [ 'isConditionMet' => false, ], 2 => [ 'isConditionMet' => true, ], 3 => [ 'isConditionMet' => false, ], ], ]; this is the result of checking occurrences of an event in 2 hours period of data shown in 2 different timeframes: 1 hour and 30 minutes, since its 2 hours of data, we have 2 items in 1h and 4 based on 30 minutes timeframes. so each item in 1h array corresponds with 2 items in 30m array. the problem in here is that I want to make sure if a condition has happend on a higher timeframe (1h in here), there must be at least one occurrences of that on its shorter timeframe (30m in here), so for the example above, the condition is met on second hour, which corresponds with items of 2 and 3 on it's shorter timeframe, so i know its a match. but there is a catch in here: [list] [*]number of items in $results are dynamic, it might have 1 item or multiple items. [*]timeframes are also dynamic, available timeframes are: ['1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '8h', '12h', '1d', '3d', '1w', '1M']; [*]there might be multiple items of the same timeframe, i mean there might be multiple 1h timeframes in the $results array. [/list] what I have so far:
function findSequentialMatch($results) { // Timeframe to minutes mapping for calculations $timeframeToMinutes = [ '1m' => 1, '3m' => 3, '5m' => 5, '15m' => 15, '30m' => 30, '1h' => 60, '2h' => 120, '4h' => 240, '6h' => 360, '8h' => 480, '12h' => 720, '1d' => 1440, '3d' => 4320, '1w' => 10080, '1M' => 43200 ]; // Extract and sort timeframes from the results based on their duration in descending order $timeframes = array_keys($results); usort($timeframes, function ($a, $b) use ($timeframeToMinutes) { return $timeframeToMinutes[$b] - $timeframeToMinutes[$a]; }); // Validate sequential match for each timeframe against its next shorter timeframe for ($i = 0; $i < count($timeframes) - 1; $i++) { $currentLongerTimeframe = $timeframes[$i]; $currentShorterTimeframe = $timeframes[$i + 1]; $ratio = $timeframeToMinutes[$currentLongerTimeframe] / $timeframeToMinutes[$currentShorterTimeframe]; foreach ($results[$currentLongerTimeframe] as $index => $condition) { if ($condition['isConditionMet']) { $foundMatchInShorterTimeframe = false; $start = $index * $ratio; $end = $start + $ratio - 1; for ($j = $start; $j
Я хочу сопоставить значение в столбце базы данных, используя Karate для моей автоматизации API.
Я сделал, как показано ниже.
* def test= db.readRow( select * from testdb.col xyz where xyz.id = ' )
Я пытаюсь последовательно выполнить два метода тестирования, один из которых — junit, а другой — Android Test. Будет выполнен первый метод тестирования junit, за которым последует тест Android. Я не хочу выполнять это вручную, и есть ли способ...
00 if none is pressed. 10 if left is pressed but right is not. 01 if right is pressed but left is not. 11 if both are pressed and call the take damage function.
Я разрабатываю приложение структурированной потоковой передачи Apache Spark, которому необходимо сначала обработать исторические данные, хранящиеся в виде файлов Avro (это архивные файлы Kafka) в HDFS, а затем, когда они будут полностью завершены,...
Я разрабатываю приложение структурированной потоковой передачи Apache Spark, которому необходимо сначала обработать исторические данные, хранящиеся в виде файлов Avro (это архивные файлы Kafka) в HDFS, а затем, когда они будут полностью завершены,...