读取txt中的字段key,然后编号再输出

import pandas as pd
sep="|"

def read_key(dict_key, arr_fileld, idx=[]):
    if len(idx) == 0:
        return
    for index in idx:
        keys = arr_fileld[index].split(",")
        for key in keys:
            if key not in dict_key:
                dict_key[key] = len(dict_key) + 1

def replace_key(dict_key, arr_fileld, idx=[]):
    if len(idx) == 0:
        return ""
    res = []
    for i in range(len(arr_fileld)):
        if i in idx:
            keys = arr_fileld[i].split(",")
            ids = []
            for key in keys:
                ids.append(str(dict_key[key]))
            res.append(",".join(ids))
        else:
            res.append(arr_fileld[i])
    return "|".join(res)


def read_file(file_name,file_out,idx):

    with open(file_name,"r",encoding="utf-8") as f:
        dict_key = {}
        for line in f:
            read_key(dict_key, line.split(sep), idx)
    with open(file_name,"r",encoding="utf-8") as f:
        with open(file_out,"w",encoding="utf-8") as fout:
            for line in f:
                res = replace_key(dict_key,line.split(sep),idx)
                fout.write(res)


import json

with open("../conf/names.json", 'r') as f:
    names = json.load(f)
idx = []


for i,name in enumerate(names):
    if "room_id" in name or ("room" in name and "idx" in name):
        idx.append(i)


from datetime import datetime
cur_time1 = datetime.now()
read_file("../data/xxx", "../data/out",idx)
cur_time2 = datetime.now()

time_span = cur_time2 -cur_time1
print("time", time_span)

 

在 C# 中,上传阿里云 OSS (Object Storage Service) 文件并实时更新数据库中的进度字段,通常需要通过阿里云 SDK 进行操作,并结合异步任务来处理上传过程中的进度。以下是一个基本步骤: 1. 首先,你需要安装对应的 Alibaba Cloud SDK for .NET,可以从其 GitHub 上获取库:https://github.com/Aliyun-OSS/dotnet-sdk 2. 创建一个 `OSSClient` 对象,用于连接到 OSS 存储。 ```csharp using Alibaba.OSS; string endpoint = "your_oss_endpoint"; string accessKeyId = "your_access_key_id"; string accessKeySecret = "your_access_key_secret"; string bucketName = "your_bucket_name"; var client = new OSSClient(endpoint, accessKeyId, accessKeySecret); ``` 3. 使用 `UploadPartAsync` 方法上传文件,并传递一个回调函数来处理上传进度。这个回调会接收一个 `ProgressEvent` 参数,该对象包含当前上传的部分大小、总大小以及上传百分比。 ```csharp string objectName = "your_object_name"; Stream fileStream = File.OpenRead("local_file_path"); int partSize = 5 * 1024 * 1024; // 每部分大小,单位字节 long totalSize = fileStream.Length; long uploadedBytes = 0; long lastUploadedBytes = 0; client.UploadPartAsync(bucketName, objectName, partSize, ProgressHandler((eventArgs) => { if (eventArgs.ProgressPercentage > lastUploadedBytes) { UpdateDatabase(objectName, eventArgs.TransferredSize, totalSize); // 更新数据库中的进度 lastUploadedBytes = eventArgs.TransferredSize; } }, fileStream); ``` 在这里,`UpdateDatabase` 函数应该是一个异步方法,将上传的部分大小(`eventArgs.TransferredSize`)存储到数据库对应字段中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值