php - Sorting and selecting from sql table by time zone -


i have question seams me complicated of can easy. here is: have mysql table

id  |  username  |  time_zone | selected  1      xxx           +4          1  2      xxx           -6          0  3      xxx           null        1 

and on. number of rows can more million. (note there can users time zone undefined.) there php script runs every hour via cron job , selects amount of rows table. difficult part.

  1. the number of rows selected table must equal each hour. (amount selected = count()/24)
  2. each of rows must not selected more once per day(that's why have added column "selected" in table).
  3. every user must selected when local time 1pm 5pm.
  4. if user`s time zone undefined must selected 5pm 8pm.
  5. if amount of users not enough specific time e.g. user count time zone +4 less count()/24, equality can compensated undefined users or users neighbor time zones.
  6. if there many users specified time can passed next neighbor time zone.

i don`t need code logic. if can great full. if there questions can go in more details.

you have bin packing problem. made more complicated "borrowing neighboring timezones". here ideas on how can approach problem.

here 1 way think solution:

  1. add column "used time zone" table (you can re-use selected if want)
  2. randomly choose 1 user each time zone among users haven't been selected
  3. assign into time zone
  4. if there no users time zone, @ neighboring zones user
  5. iterate again nth person in each bucket

oh, seems complicated. seems bunch of cursors needed solve problem.

instead, let's populate time zone instead of user.

  1. start populous available time zone
  2. randomly select available users time zone , set "used time zone" time zone
  3. if there not enough users, go previous time zones , select excess available users.
  4. iterate on time zones

this getting close. can further optimize assigning users time zones @ once. then, time zones not full, go , pick excess users other time zones.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -