Commit 857d6184 authored by 潘栩锋's avatar 潘栩锋 🚴

生成模拟数据,测试数据库浏览器

parent 84fba439
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BC3B8548-3586-4FD1-ADDE-3E524825848D}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ConsoleApp1</RootNamespace>
<AssemblyName>ConsoleApp1</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Project.FLY.Thick.FilmCasting\FLY.Thick.FilmCasting\FLY.Thick.FilmCasting.csproj">
<Project>{e2bd6ff0-64c5-46fb-aa37-9b1f75ec6500}</Project>
<Name>FLY.Thick.FilmCasting</Name>
</ProjectReference>
<ProjectReference Include="..\thick_public\Project.SQLiteHelper\SQLiteHelper\SQLiteHelper.csproj">
<Project>{4cbabfaa-1c62-4510-ac63-a51ee5fd50ff}</Project>
<Name>SQLiteHelper</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper">
<Version>10.1.1</Version>
</PackageReference>
<PackageReference Include="System.Data.SQLite">
<Version>1.0.112</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using FLY.Thick.FilmCasting.Server.Model;
using SQLite;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
public class TestDb
{
DbModel dbModel;
static void Main(string[] args)
{
Console.WriteLine("生成假数据库数据");
TestDb p = new TestDb();
p.Init();
p.Debug_Db();
Console.Read();
}
public void Init()
{
//手动先删除数据库
//@"D:\film_casting_data\thickness.sqlite3"
Directory.Delete(@"D:\film_casting_data", true);
dbModel = new DbModel();
dbModel.Init();
}
public void Debug_Db()
{
//创建8个月的数据
DateTime startTime = DateTime.Now - TimeSpan.FromDays(30 * 8);
DateTime time = startTime;
DateTime sampleTime = DateTime.MinValue;
int number = 0;
int boltCnt = 120;
Db_Profile profile = new Db_Profile()
{
ID = dbModel.TbProfile.FreeID,
PName = "abc",
Batch = "abc",
Number = number.ToString(),
StartTime = time,
EndTime = time,
ScanBegin = 10,
ScanEnd = boltCnt - 1 - 10,
Target = 110,
TolerancePercent = 0.03,
IsFinished = false
};
double position = 0;
double filmVelocity = 20;
Random r = new Random();
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
List<string> sqls = new List<string>();
int cnt = 0;
int sample0Ad = 50300;
int leftNoUsed = 10;
int rightNoUsed = 12;
double filmWidth = (boltCnt - leftNoUsed - rightNoUsed) * 25.4 * (1 - 0.03);
while (time < DateTime.Now)
{
//每1小时1个产品
//每10分钟添加一条样品
if ((sampleTime == DateTime.MinValue) || (time - sampleTime > TimeSpan.FromMinutes(10)))
{
sampleTime = time;
sample0Ad = 50300 + r.Next(50) - 25;
Lc_Sample sampleData = new Lc_Sample()
{
Time = time,
SampleADs = new int[] { sample0Ad, -1, -1 }
};
sampleData.ID = dbModel.TbSample.FreeID;
var db_sampleData = Lc_AutoMapperProfile.Mapper.Map<Db_Sample>(sampleData);
sqls.Add(SQLiteHelper.GetInsertCommandText(db_sampleData));
}
//每次都添加扫描数据
Lc_ScanData lc_ScanData;
{
double[] datas = new double[boltCnt];
for (int i = 0; i < boltCnt; i++)
{
datas[i] = double.NaN;
}
for (int i = leftNoUsed; i < boltCnt - rightNoUsed; i++)
{
datas[i] = (r.NextDouble() - 0.5) * 0.02 * profile.Target + profile.Target;
}
lc_ScanData = new Lc_ScanData()
{
ID = dbModel.TbScanData.FreeID,
Time = time - TimeSpan.FromSeconds(25),
EndTime = time,
K = 1,
B = 0,
FilmPosition = Math.Round(position, 2),
FilmVelocity = filmVelocity,
FilmWidth = (int)(filmWidth + (r.NextDouble() - 0.5) * 3),
Thicks = datas,
SampleADs = new int[] { sample0Ad, -1, -1 },
Target = profile.Target,
TolerancePercent = profile.TolerancePercent
};
var db_ScanData = Lc_AutoMapperProfile.Mapper.Map<Db_ScanData>(lc_ScanData);
sqls.Add(SQLiteHelper.GetInsertCommandText(db_ScanData));
}
time += TimeSpan.FromSeconds(30);
position += filmVelocity * 7 / 60;
profile.EndTime = time;
if (time - profile.StartTime > TimeSpan.FromMinutes(60))
{
//换卷
var db_profile = Lc_AutoMapperProfile.Mapper.Map<Db_Profile>(profile);
sqls.Add(SQLiteHelper.GetInsertCommandText(db_profile));
//全部数据写入
cnt++;
if (cnt > 24)
{
dbModel.sqliteHelper.QueryTran(sqls);
sqls.Clear();
cnt = 0;
stopwatch.Stop();
TimeSpan ts = stopwatch.Elapsed;
stopwatch.Restart();
double sec = (DateTime.Now - time).TotalDays * ts.TotalSeconds;
ts = TimeSpan.FromSeconds(sec);
//每24小时保存一次
Console.WriteLine($"number={number} time={time:MM/dd} 估计剩余:{ts.TotalMinutes:F1}分钟");
}
number++;
position = 0;
profile.ID = dbModel.TbProfile.FreeID;
profile.Number = number.ToString();
profile.StartTime = time;
profile.EndTime = time;
}
}
//保存最后一个
{
var db_profile = Lc_AutoMapperProfile.Mapper.Map<Db_Profile>(profile);
sqls.Add(SQLiteHelper.GetInsertCommandText(db_profile));
//全部数据写入
dbModel.sqliteHelper.QueryTran(sqls);
sqls.Clear();
Console.WriteLine($"number={number} time={time:yyyy/MM/dd HH:mm} 完成");
}
//备份上一个月之前的数据到 yyyy-MM 文件夹
Console.WriteLine($"备份上一个月之前的数据到 yyyy-MM 文件夹");
dbModel.BackupBbInSize(12);
//当前的数据库只保存上个月与这个月的数据
Console.WriteLine($"当前的数据库只保存上个月与这个月的数据");
dbModel.KeepDBSize(1);
Console.WriteLine($"完成");
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("ConsoleApp1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConsoleApp1")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("bc3b8548-3586-4fd1-adde-3e524825848d")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment