dongyoufo5672 2013-02-01 13:54
浏览 28
已采纳

工厂可用性监视器的想法[已关闭]

What I want to do is set up a page that can monitor the availability of a piece of plant, i.e. how many hours in a day was a JCB working? I'd like to have a single button that will change the status of the plant (easy) on a page but I'd like to track when the status changed and then be able to calculate the availability for a given period (the bit I'm stuck on).

I'm struggling to think of how I can structure the database and php script to allow me to do this... Any ideas/help greatly appreciated :)

  • 写回答

2条回答 默认 最新

  • douxian4376 2013-02-01 14:18
    关注

    You could structure your table with columns for JCB ID, start time, and end time like below

    jcb_id    start_time               stop_time
    1         2013-01-31 00:00:00      2013-01-31 06:19:00
    1         2013-01-31 21:04:00      null
    2         2013-01-31 08:00:45      2013-01-31 18:19:00
    

    In the example above:

    • jcb_id 1 is currently active because the stop_time is null.
    • jcb_id 2 is down because there is no record with a null stop time.

    When you click the button, the page will check to see if there is a record for the JCB with a null stop_time.

    • select from the jcb table where jcb_id = ? and stop_time is null
    • If a null stop time exists for the JCB,
      • update the record with NOW() - JCB is not working
    • Else - there is no null stop time record for the JCB
      • insert a new record, leaving stop_time null - JCB is working

    From there, you can run a query to calculate the time between the starts and stops to get up/downtime.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c