duandian2725 2019-05-15 14:05
浏览 35

计算x事件的重叠

The task is to calculate the overlap of events (stored in DB) and show the overlapping times as events. So if I have 3 Users and they have events spread through the day and there are times all 3 Users overlap I want to create an event representing that time and show it on the frontend.

Monday: User1 has Event 12:00-13:00 User2 has Event12:45-13:45 User3 has Event 12:30-14:00

Would give the overlapEvent 12:45-13:00

I have a database with the tables calendar and calendar_events. the calendar represents a user-calendar and calendar_events has all events. Events have the pid field to refer the calendar it belongs to. I have a method that returns all events for each day in the week. I have tried running over all events each day x times (x is the number of users, whose overlap I need to calculate) in for loops, but this seems very inefficient since the processing time increase exponentially with each user. I have tried creating a new array with the pid field as keys, but I don't really know where to go from here. I need to check each event against all events of that day from the other users.

$overlapEvents=array();
 foreach ($AllEvents as $key => $days) 
{
            $eventsSorted=array();
            foreach ($days as $day => $events) 
{

                foreach ($events as $event) 
{
                         array_push($eventSorted[$event['pid'],$event);

}
}
}

This is how $AllEvents looks like

Array
(
    [20190516] => Array //date of day 2019 05 16
        (
            [1558002600] => Array//event start time
                (
                    [0] => Array
                        (
                            [id] => 645
                            [pid] => 16
                            [tstamp] => 1557905849
                            [title] => testEvent
                            [alias] => testEvent
                            [author] => 1
                            [addTime] => 1
                            [startTime] => 1558002600
                            [endTime] => 1558003500
                            [startDate] => 1557957600
                            [endDate] => 1557957600
                            )
   )

)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 运动想象脑电信号数据集.vhdr
    • ¥15 三因素重复测量数据R语句编写,不存在交互作用
    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目