欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于Python編寫監(jiān)控視頻存儲計算器

 更新時間:2024年12月19日 09:59:26   作者:PieroPc  
這篇文章主要為大家詳細(xì)介紹了如何基于Python編寫一個監(jiān)控視頻存儲計算器,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

這篇文章主要來和大家介紹一下如何使用Python開發(fā)一個簡單的監(jiān)控視頻存儲計算器,下面是示例代碼,希望對大家有所幫助

完整代碼

import tkinter as tk
from tkinter import ttk
import math
from tkinter.font import Font
 
class StorageCalculator:
    def __init__(self, root):
        self.root = root
        self.root.title("監(jiān)控視頻存儲計算器")
        self.root.geometry("600x800")
        self.root.configure(bg='#f0f0f0')
        
        # 設(shè)置主題和樣式
        self.style = ttk.Style()
        self.style.theme_use('clam')  # 使用clam主題作為基礎(chǔ)
        
        # 定義顏色方案
        self.colors = {
            'primary': '#2196F3',    # 主色調(diào)
            'secondary': '#64B5F6',   # 次要色調(diào)
            'bg': '#f0f0f0',         # 背景色
            'text': '#212121',       # 文字顏色
            'success': '#4CAF50'     # 成功色
        }
        
        # 設(shè)置自定義字體
        self.title_font = Font(family="微軟雅黑", size=12, weight="bold")
        self.normal_font = Font(family="微軟雅黑", size=10)
        self.result_font = Font(family="微軟雅黑", size=11, weight="bold")
        
        # 配置樣式
        self.style.configure('Title.TLabel', 
                           font=self.title_font, 
                           background=self.colors['bg'],
                           foreground=self.colors['primary'])
        
        self.style.configure('Normal.TLabel', 
                           font=self.normal_font,
                           background=self.colors['bg'])
        
        self.style.configure('Custom.TButton',
                           font=self.normal_font,
                           background=self.colors['primary'],
                           padding=(20, 10))
        
        self.style.configure('Tab.TNotebook',
                           background=self.colors['bg'])
        
        self.style.configure('Result.TLabelframe',
                           background=self.colors['bg'])
        
        # 創(chuàng)建主標(biāo)題
        self.create_header()
        
        # 創(chuàng)建notebook
        self.notebook = ttk.Notebook(root, style='Tab.TNotebook')
        self.notebook.pack(fill='both', expand=True, padx=20, pady=(0, 20))
        
        # 創(chuàng)建計算頁面
        self.create_forward_page()
        self.create_reverse_page()
        
        # 創(chuàng)建頁腳
        self.create_footer()
 
    def create_header(self):
        """創(chuàng)建頭部標(biāo)題區(qū)域"""
        header_frame = ttk.Frame(self.root)
        header_frame.pack(fill='x', padx=20, pady=20)
        
        title = ttk.Label(header_frame, 
                         text="監(jiān)控視頻存儲計算器",
                         style='Title.TLabel')
        title.pack()
        
        subtitle = ttk.Label(header_frame,
                           text="專業(yè)的存儲空間評估工具",
                           style='Normal.TLabel')
        subtitle.pack()
 
    def create_forward_page(self):
        """創(chuàng)建正向計算頁面"""
        self.forward_frame = ttk.Frame(self.notebook, padding="20")
        self.notebook.add(self.forward_frame, text=" 計算存儲需求 ")
        
        # 創(chuàng)建輸入?yún)^(qū)域
        input_frame = ttk.LabelFrame(self.forward_frame, 
                                   text="參數(shù)輸入",
                                   padding="15")
        input_frame.pack(fill='x', padx=10, pady=5)
        
        # 添加輸入控件
        self.create_input_field(input_frame, "攝像頭數(shù)量:", 0, self.normal_font)
        self.cameras = self.entry
        
        self.create_input_field(input_frame, "每天錄像時間(小時):", 1, self.normal_font)
        self.hours = self.entry
        self.hours.insert(0, "24")  # 默認(rèn)24小時
        
        self.create_input_field(input_frame, "需要保存的天數(shù):", 2, self.normal_font)
        self.days = self.entry
        
        # 攝像頭類型選擇
        ttk.Label(input_frame, text="攝像頭類型:", 
                 font=self.normal_font).grid(row=3, column=0, 
                 sticky=tk.W, pady=5)
        
        self.camera_type = ttk.Combobox(input_frame, width=25,
                                      font=self.normal_font)
        self.camera_type['values'] = ['200萬像素', '300萬像素', '400萬像素', '500萬像素']
        self.camera_type.current(0)
        self.camera_type.grid(row=3, column=1, sticky=tk.W, pady=5)
        
        # 編碼方式選擇
        ttk.Label(input_frame, text="編碼方式:", 
                 font=self.normal_font).grid(row=4, column=0, 
                 sticky=tk.W, pady=5)
        
        self.encoding = ttk.Combobox(input_frame, width=25,
                                   font=self.normal_font)
        self.encoding['values'] = ['H.264', 'H.265']
        self.encoding.current(1)  # 默認(rèn)H.265
        self.encoding.grid(row=4, column=1, sticky=tk.W, pady=5)
        
        # 計算按鈕
        btn_frame = ttk.Frame(self.forward_frame)
        btn_frame.pack(fill='x', pady=20)
        
        calc_btn = ttk.Button(btn_frame, 
                            text="計算存儲需求",
                            style='Custom.TButton',
                            command=self.calculate_forward)
        calc_btn.pack(expand=True)
        
        # 結(jié)果顯示區(qū)域
        self.forward_result_frame = ttk.LabelFrame(self.forward_frame,
                                                 text="計算結(jié)果",
                                                 padding="15",
                                                 style='Result.TLabelframe')
        self.forward_result_frame.pack(fill='x', padx=10, pady=5)
        
        self.storage_label = ttk.Label(self.forward_result_frame,
                                     text="",
                                     font=self.result_font)
        self.storage_label.pack(anchor=tk.W)
        
        self.recommendation_label = ttk.Label(self.forward_result_frame,
                                            text="",
                                            font=self.result_font)
        self.recommendation_label.pack(anchor=tk.W)
 
    def create_reverse_page(self):
        """創(chuàng)建反向計算頁面"""
        self.reverse_frame = ttk.Frame(self.notebook, padding="20")
        self.notebook.add(self.reverse_frame, text=" 計算存儲時間 ")
        
        # 創(chuàng)建輸入?yún)^(qū)域
        input_frame = ttk.LabelFrame(self.reverse_frame,
                                   text="參數(shù)輸入",
                                   padding="15")
        input_frame.pack(fill='x', padx=10, pady=5)
        
        # 添加輸入控件
        self.create_input_field(input_frame, "硬盤容量(TB):", 0, self.normal_font)
        self.storage_size = self.entry
        
        self.create_input_field(input_frame, "攝像頭數(shù)量:", 1, self.normal_font)
        self.rev_cameras = self.entry
        
        self.create_input_field(input_frame, "每天錄像時間(小時):", 2, self.normal_font)
        self.rev_hours = self.entry
        
        # 攝像頭類型選擇
        ttk.Label(input_frame, text="攝像頭類型:",
                 font=self.normal_font).grid(row=3, column=0,
                 sticky=tk.W, pady=5)
        
        self.rev_camera_type = ttk.Combobox(input_frame, width=25,
                                          font=self.normal_font)
        self.rev_camera_type['values'] = ['200萬像素', '300萬像素', '400萬像素', '500萬像素']
        self.rev_camera_type.current(0)
        self.rev_camera_type.grid(row=3, column=1, sticky=tk.W, pady=5)
        
        # 編碼方式選擇
        ttk.Label(input_frame, text="編碼方式:",
                 font=self.normal_font).grid(row=4, column=0,
                 sticky=tk.W, pady=5)
        
        self.rev_encoding = ttk.Combobox(input_frame, width=25,
                                       font=self.normal_font)
        self.rev_encoding['values'] = ['H.264', 'H.265']
        self.rev_encoding.current(1)  # 默認(rèn)H.265
        self.rev_encoding.grid(row=4, column=1, sticky=tk.W, pady=5)
        
        # 計算按鈕
        btn_frame = ttk.Frame(self.reverse_frame)
        btn_frame.pack(fill='x', pady=20)
        
        calc_btn = ttk.Button(btn_frame,
                            text="計算可存儲天數(shù)",
                            style='Custom.TButton',
                            command=self.calculate_reverse)
        calc_btn.pack(expand=True)
        
        # 結(jié)果顯示區(qū)域
        self.reverse_result_frame = ttk.LabelFrame(self.reverse_frame,
                                                 text="計算結(jié)果",
                                                 padding="15",
                                                 style='Result.TLabelframe')
        self.reverse_result_frame.pack(fill='x', padx=10, pady=5)
        
        self.days_label = ttk.Label(self.reverse_result_frame,
                                  text="",
                                  font=self.result_font)
        self.days_label.pack(anchor=tk.W)
 
    def create_footer(self):
        """創(chuàng)建頁腳"""
        footer = ttk.Label(self.root,
                          text="? 2024 專業(yè)視頻監(jiān)控存儲解決方案",
                          style='Normal.TLabel')
        footer.pack(pady=10)
 
    def create_input_field(self, parent, label_text, row, font):
        """創(chuàng)建統(tǒng)一的輸入字段"""
        ttk.Label(parent, text=label_text,
                 font=font).grid(row=row, column=0,
                 sticky=tk.W, pady=5)
        
        self.entry = ttk.Entry(parent, width=25,
                             font=font)
        self.entry.grid(row=row, column=1, sticky=tk.W, pady=5)
        return self.entry
 
    def calculate_storage(self, cameras, hours_per_day, days, camera_type, encoding):
        """
        計算存儲需求
        camera_type: 攝像頭類型 (200萬/300萬/400萬/500萬)
        encoding: 編碼方式 (H.264/H.265)
        """
        # 每天存儲空間(GB)
        daily_storage = {
            '200萬像素': {
                'H.264': 42.19,  # 4096kbps
                'H.265': 21.09   # 2048kbps
            },
            '300萬像素': {
                'H.264': 42.19,  # 4096kbps
                'H.265': 21.09   # 2048kbps
            },
            '400萬像素': {
                'H.264': 42.19,  # 4096kbps
                'H.265': 21.09   # 2048kbps
            },
            '500萬像素': {
                'H.264': 63.28,  # 6144kbps
                'H.265': 31.64   # 3072kbps
            }
        }
        
        # 計算單個攝像頭每天實際存儲量
        daily_per_camera = daily_storage[camera_type][encoding] * (hours_per_day / 24)
        
        # 計算總存儲量
        total_storage_gb = daily_per_camera * cameras * days
        
        # 轉(zhuǎn)換為TB并返回
        return round(total_storage_gb / 1024, 2)
 
    def calculate_days(self, storage_tb, cameras, hours_per_day, camera_type, encoding):
        """
        計算可存儲天數(shù)
        """
        daily_storage = {
            '200萬像素': {
                'H.264': 42.19,
                'H.265': 21.09
            },
            '300萬像素': {
                'H.264': 42.19,
                'H.265': 21.09
            },
            '400萬像素': {
                'H.264': 42.19,
                'H.265': 21.09
            },
            '500萬像素': {
                'H.264': 63.28,
                'H.265': 31.64
            }
        }
        
        # 計算單個攝像頭每天實際存儲量
        daily_per_camera = daily_storage[camera_type][encoding] * (hours_per_day / 24)
        
        # 計算可存儲天數(shù)
        total_gb = storage_tb * 1024
        days = total_gb / (daily_per_camera * cameras)
        return round(days, 1)
 
    def calculate_forward(self):
        try:
            cameras = int(self.cameras.get())
            hours = float(self.hours.get())
            days = int(self.days.get())
            camera_type = self.camera_type.get()
            encoding = self.encoding.get()
            
            if cameras <= 0 or hours <= 0 or days <= 0:
                raise ValueError("請輸入大于0的數(shù)值")
            
            # 獲取單個攝像頭每天的存儲量
            daily_storage = {
                '200萬像素': {
                    'H.264': 42.19,
                    'H.265': 21.09
                },
                '300萬像素': {
                    'H.264': 42.19,
                    'H.265': 21.09
                },
                '400萬像素': {
                    'H.264': 42.19,
                    'H.265': 21.09
                },
                '500萬像素': {
                    'H.264': 63.28,
                    'H.265': 31.64
                }
            }
            
            daily_per_camera = daily_storage[camera_type][encoding] * (hours / 24)
            daily_total = daily_per_camera * cameras
            
            storage = self.calculate_storage(cameras, hours, days, camera_type, encoding)
            
            self.storage_label.config(
                text=f"每天存儲空間: {round(daily_total, 2)} GB/天\n"
                     f"總存儲容量: {storage} TB",
                foreground=self.colors['success'])
            self.recommendation_label.config(
                text=f"建議配置: {math.ceil(storage)} TB 硬盤\n"
                     f"(基于{camera_type}攝像頭,{encoding}編碼)\n"
                     f"單個攝像頭: {round(daily_per_camera, 2)} GB/天",
                foreground=self.colors['success'])
            
        except ValueError as e:
            self.storage_label.config(
                text="輸入錯誤!",
                foreground='red')
            self.recommendation_label.config(
                text="請檢查輸入的數(shù)值是否正確",
                foreground='red')
 
    def calculate_reverse(self):
        try:
            storage = float(self.storage_size.get())
            cameras = int(self.rev_cameras.get())
            hours = float(self.rev_hours.get())
            camera_type = self.rev_camera_type.get()
            encoding = self.rev_encoding.get()
            
            if storage <= 0 or cameras <= 0 or hours <= 0:
                raise ValueError("請輸入大于0的數(shù)值")
            
            # 獲取單個攝像頭每天的存儲量
            daily_storage = {
                '200萬像素': {
                    'H.264': 42.19,
                    'H.265': 21.09
                },
                '300萬像素': {
                    'H.264': 42.19,
                    'H.265': 21.09
                },
                '400萬像素': {
                    'H.264': 42.19,
                    'H.265': 21.09
                },
                '500萬像素': {
                    'H.264': 63.28,
                    'H.265': 31.64
                }
            }
            
            daily_per_camera = daily_storage[camera_type][encoding] * (hours / 24)
            daily_total = daily_per_camera * cameras
            
            days = self.calculate_days(storage, cameras, hours, camera_type, encoding)
            
            self.days_label.config(
                text=f"每天存儲空間: {round(daily_total, 2)} GB/天\n"
                     f"單個攝像頭: {round(daily_per_camera, 2)} GB/天\n"
                     f"可存儲天數(shù): {days} 天\n"
                     f"約等于 {round(days/30, 1)} 個月 或 {round(days/365, 1)} 年\n"
                     f"(基于{camera_type}攝像頭,{encoding}編碼)",
                foreground=self.colors['success'])
            
        except ValueError as e:
            self.days_label.config(
                text="輸入錯誤!\n請檢查輸入的數(shù)值是否正確",
                foreground='red')
 
def main():
    root = tk.Tk()
    app = StorageCalculator(root)
    root.mainloop()
 
if __name__ == "__main__":
    main()

效果圖

到此這篇關(guān)于基于Python編寫監(jiān)控視頻存儲計算器的文章就介紹到這了,更多相關(guān)Python監(jiān)控視頻存儲計算器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python可視化神器pyecharts繪制漏斗圖

    Python可視化神器pyecharts繪制漏斗圖

    這篇文章主要介紹了Python可視化神器pyecharts繪制漏斗圖,漏斗圖是由Light等在1984年提出,一般以單個研究的效應(yīng)量為橫坐標(biāo),樣本含量為縱坐標(biāo)做的散點圖
    2022-07-07
  • python requests指定出口ip的例子

    python requests指定出口ip的例子

    今天小編就為大家分享一篇python requests指定出口ip的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-07-07
  • Python繪圖系統(tǒng)之散點圖和條形圖的實現(xiàn)代碼

    Python繪圖系統(tǒng)之散點圖和條形圖的實現(xiàn)代碼

    這篇文章主要為大家詳細(xì)介紹了如何使用Python繪制散點圖和條形圖,文中的示例代碼講解詳細(xì),對我們的學(xué)習(xí)或工作有一定的幫助,感興趣的可以了解一下
    2023-08-08
  • python函數(shù)局部變量、全局變量、遞歸知識點總結(jié)

    python函數(shù)局部變量、全局變量、遞歸知識點總結(jié)

    在本篇文章里小編給大家整理了關(guān)于python函數(shù)局部變量、全局變量、遞歸知識點,有興趣的朋友們學(xué)習(xí)參考下。
    2019-11-11
  • Pyqt5 關(guān)于流式布局和滾動條的綜合使用示例代碼

    Pyqt5 關(guān)于流式布局和滾動條的綜合使用示例代碼

    這篇文章主要介紹了Pyqt5 關(guān)于流式布局和滾動條的綜合使用示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • tensorflow中tf.reduce_mean函數(shù)的使用

    tensorflow中tf.reduce_mean函數(shù)的使用

    這篇文章主要介紹了tensorflow中tf.reduce_mean函數(shù)的使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • tensorflow 報錯unitialized value的解決方法

    tensorflow 報錯unitialized value的解決方法

    今天小編就為大家分享一篇tensorflow 報錯unitialized value的解決方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-02-02
  • 30分鐘搭建Python的Flask框架并在上面編寫第一個應(yīng)用

    30分鐘搭建Python的Flask框架并在上面編寫第一個應(yīng)用

    這篇文章主要介紹了如何搭建Python的Flask框架并在上面編寫一個簡單的登錄模版應(yīng)用,代碼數(shù)量少、充分體現(xiàn)了Flask框架的輕量與開發(fā)高效的特點,需要的朋友可以參考下
    2015-03-03
  • Python實現(xiàn)的簡單發(fā)送郵件腳本分享

    Python實現(xiàn)的簡單發(fā)送郵件腳本分享

    這篇文章主要介紹了Python實現(xiàn)的簡單發(fā)送郵件腳本分享,本文使用smtplib模塊實現(xiàn)郵件的發(fā)送,需要的朋友可以參考下
    2014-11-11
  • 利用Python將list列表寫入文件并讀取的方法匯總

    利用Python將list列表寫入文件并讀取的方法匯總

    因為實驗需要,實現(xiàn)了一下寫入txt文件,下面這篇文章主要給大家介紹了關(guān)于如何利用Python將list列表寫入文件并讀取的幾種方法,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-03-03

最新評論