You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于固定非线性设备使用日历,计算指定日期寿命及预测维护任务到期日

Hey Harry, let's tackle these two practical asset management problems one by one—both come up often in industrial or fleet management systems, so I’ve got actionable, step-by-step approaches for you.

1. Calculating Device Lifespan on a Specific Date (Fixed Nonlinear Usage Calendar)

First, let's clarify the core variables we need here:

  • The device’s total rated lifespan (e.g., 50,000 minutes of operation before replacement/maintenance)
  • A nonlinear usage calendar that tracks exactly when and how much the device was used (or is scheduled to be used) up to your target date

Here’s how to compute the lifespan as of your specified date:

  • Step 1: Extract relevant usage data
    Go through your nonlinear calendar and pull every usage entry that falls on or before the target date. Since it's nonlinear, entries might be one-off dates with specific usage times, or date ranges with daily usage values—make sure to capture all of them.
  • Step 2: Sum accumulated usage
    Convert all entries to a consistent unit (stick to minutes, since your second problem uses integer minute storage) and add them up to get the total time the device has been used by the target date.
  • Step 3: Compute remaining lifespan
    Subtract the accumulated usage from the device’s total rated lifespan. If you want a percentage instead, divide accumulated usage by total lifespan and multiply by 100.

Example

Suppose your device has a 30,000-minute rated lifespan, and your nonlinear calendar includes:

  • 2024-01-01 to 2024-01-10: 120 minutes of use per day
  • 2024-01-15: 300 minutes of use
  • Target date: 2024-01-16

Total accumulated usage = (10 * 120) + 300 = 1,500 minutes
Remaining lifespan = 30,000 - 1,500 = 28,500 minutes

Quick Code Snippet (Python)

from datetime import datetime

def calculate_remaining_lifespan(total_lifespan_min, usage_calendar, target_date_str):
    target_date = datetime.strptime(target_date_str, "%Y-%m-%d").date()
    accumulated = 0
    
    for entry in usage_calendar:
        # Handle single-date entries
        if "date" in entry:
            entry_date = datetime.strptime(entry["date"], "%Y-%m-%d").date()
            if entry_date <= target_date:
                accumulated += entry["usage_min"]
        # Handle date-range entries
        elif "start_date" in entry and "end_date" in entry:
            start = datetime.strptime(entry["start_date"], "%Y-%m-%d").date()
            end = datetime.strptime(entry["end_date"], "%Y-%m-%d").date()
            # Entire range is before target date
            if end <= target_date:
                days = (end - start).days + 1
                accumulated += days * entry["daily_min"]
            # Partial range overlaps with target date
            elif start <= target_date:
                days = (target_date - start).days + 1
                accumulated += days * entry["daily_min"]
    
    return total_lifespan_min - accumulated

# Example usage
device_lifespan = 30000
calendar = [
    {"start_date": "2024-01-01", "end_date": "2024-01-10", "daily_min": 120},
    {"date": "2024-01-15", "usage_min": 300}
]
print(calculate_remaining_lifespan(device_lifespan, calendar, "2024-01-16"))  # Output: 28500
2. Predicting Task Due Dates (Monthly Usage Data + Interval-Based Tasks)

For this problem, we’re dealing with tasks that trigger after a specific amount of device usage (e.g., "perform maintenance every 100 hours"). Here’s how to map your monthly usage data to task due dates:

Key Setup

  • Convert all monthly usage hours to minutes (since your data is stored as integer minutes: hours * 60)
  • Define each task’s usage threshold (e.g., 6,000 minutes = 100 hours)
  • Know your starting point: is the task counter starting at 0, or is there pre-existing accumulated usage before your first month of data?

Step-by-Step Process

  • Step 1: Iterate through monthly usage
    Track a running total of accumulated device usage as you go through each month.
  • Step 2: Identify threshold crossings
    For each task, check if the accumulated usage (plus the current month’s total) crosses a multiple of the task’s threshold (e.g., 6k, 12k, 18k minutes for a 6k-minute task).
  • Step 3: Calculate exact due date
    Assume uniform daily usage for the month (adjust if you have a daily usage calendar) to estimate the exact day within the month when the threshold is hit.

Example

Suppose Task A triggers every 6,000 minutes (100 hours), starting from 0 usage. Your monthly data is:

  • 2024-01: 300 hours = 18,000 minutes
  • 2024-02: 100 hours = 6,000 minutes

Calculations:

  • 1st trigger at 6k minutes: Daily avg usage in Jan = 18000 / 31 ≈ 580.65 mins. Days needed: 6000 / 580.65 ≈ 10.33 → ~2024-01-11
  • 2nd trigger at 12k minutes: 12000 / 580.65 ≈20.67 → ~2024-01-21
  • 3rd trigger at 18k minutes: End of January (2024-01-31)
  • 4th trigger at 24k minutes: End of February (2024-02-29, since 2024 is a leap year)

Quick Code Snippet (Python)

from datetime import datetime, timedelta

def predict_task_due_dates(monthly_usage, task_threshold_min, start_date_str):
    due_dates = []
    accumulated_usage = 0
    current_date = datetime.strptime(start_date_str, "%Y-%m-%d").date()
    
    for year_month, usage_hours in monthly_usage.items():
        usage_min = usage_hours * 60
        # Get number of days in the current month
        month_end = current_date.replace(day=28) + timedelta(days=4)
        month_end = month_end - timedelta(days=month_end.day)
        days_in_month = (month_end - current_date).days + 1
        daily_avg_min = usage_min / days_in_month
        
        # Check if we hit any task thresholds this month
        while accumulated_usage + usage_min >= task_threshold_min * (len(due_dates) + 1):
            target_usage = task_threshold_min * (len(due_dates) + 1)
            usage_needed = target_usage - accumulated_usage
            days_needed = usage_needed / daily_avg_min
            due_date = current_date + timedelta(days=days_needed)
            due_dates.append(due_date.date())
        
        accumulated_usage += usage_min
        # Move to the first day of the next month
        current_date = month_end + timedelta(days=1)
    
    return due_dates

# Example usage
monthly_data = {
    "2024-01": 300,
    "2024-02": 100,
    "2024-03": 450
}
start_date = "2024-01-01"
task_threshold = 6000  # 100 hours
print(predict_task_due_dates(monthly_data, task_threshold, start_date))
# Output: [datetime.date(2024, 1, 11), datetime.date(2024, 1, 21), datetime.date(2024, 1, 31), datetime.date(2024, 2, 29), ...]

内容的提问来源于stack exchange,提问作者Harry

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:52:25