当前位置: 首页 > news >正文

MongoDB在自动化设备上的应用示例

发现MongoDB特别适合自动化检测数据的存储。。。

例如一个晶圆检测项目,定义其数据结构如下

#pragma once
#include <vector>
#include <QString>
#include <QRectF>
#include <string>
#include <memory>class tpoWafer;
class tpoDie;
class tpoDefect;class tpoWafer
{
public:std::vector<std::shared_ptr<tpoDie>>Layouts; //晶圆的layoutQRectF MaskArea;QString WaferID;QString BatchID;QString ProductID;QString StepID;QString LotID;QString EqpID;QString UnitID;QString OperatorID;QString RecipeName;QString RecipeID;int TotalDie;int OKDie;int NGDie;int TotalDefect;double Mark_x;double Mark_y;QString Judge;QString WarningLevel;int WariningCode;QString StartTime;QString EndTime;int ImageCount;QString ImagePath;
};class tpoDie
{
public:std::vector<std::shared_ptr<tpoDefect>>InspectedDefect; //检测到的缺陷double die_x;double die_y;double die_width;double die_height;double die_type;int die_model;
};class tpoDefect
{
public:int id = -1;double x = 0;double y = 0;double gray = 0;double height = 0;double width = 0;double size = 0;double roundness = 1;int type = -1;int judge = 0;QRectF bounding = QRectF(0, 0, 1, 1);bool visible = true;bool skip = false;int inspect_type = 1;int flag = -1;
};

如果用的是结构型数据库存储数据,就需要在数据库中建立3个表,wafer table,die table defect table,还要用外键进行关联。

而在MongoDB这类非关系型数据库中这些都不需要,只需按照定义的数据结构把数据写成类似json文件的domcument存到数据中就可以了。最最重要的是,当数据结构改变了,增加或者减少存储的数据时完全不需要改数据库表,这个在关系型数据库中就不行了。

bool tpoWafer::write_to_database(bsoncxx::builder::stream::document& doc)
{int idx = 0;doc <<"MaskArea_x" + std::to_string(idx) << MaskArea.x() <<"MaskArea_y" + std::to_string(idx) << MaskArea.y() <<"MaskArea_width" + std::to_string(idx) << MaskArea.width() << "MaskArea_height" + std::to_string(idx) << MaskArea.height() <<"WaferID" + std::to_string(idx) << WaferID.toStdString() <<"BatchID" + std::to_string(idx) << BatchID.toStdString() <<"ProductID" + std::to_string(idx) << ProductID.toStdString() <<"StepID" + std::to_string(idx) << StepID.toStdString() <<"LotID" + std::to_string(idx) << LotID.toStdString() <<"EqpID" + std::to_string(idx) << EqpID.toStdString() <<"UnitID" + std::to_string(idx) << UnitID.toStdString() <<"OperatorID" + std::to_string(idx) << OperatorID.toStdString() <<"RecipeName" + std::to_string(idx) << RecipeName.toStdString() <<"RecipeID" + std::to_string(idx) << RecipeID.toStdString() <<"TotalDie" + std::to_string(idx) << TotalDie <<"OKDie" + std::to_string(idx) << OKDie <<"NGDie" + std::to_string(idx) << NGDie <<"TotalDefect" + std::to_string(idx) << TotalDefect <<"Mark_x" + std::to_string(idx) << Mark_x <<"Mark_y" + std::to_string(idx) << Mark_y <<"Judge" << Judge.toStdString() <<"WarningLevel" + std::to_string(idx) << WarningLevel.toStdString() <<"WariningCode" + std::to_string(idx) << WariningCode <<"StartTime" + std::to_string(idx) << StartTime.toStdString() <<"EndTime" + std::to_string(idx) << EndTime.toStdString() <<"ImageCount" + std::to_string(idx) << ImageCount <<"ImagePath" + std::to_string(idx) << ImagePath.toStdString();for (int i = 0; i < Layouts.size(); i++){Layouts[i]->write_to_database(doc, i);}return true;
}bool tpoDefect::write_to_database(bsoncxx::builder::stream::document& doc, int idx)
{doc << "defect_info"+ std::to_string(idx) << bsoncxx::builder::stream::open_document <<"id"+ std::to_string(idx) << id <<"x" + std::to_string(idx) << x <<"t" + std::to_string(idx) << y <<"gray" + std::to_string(idx) << gray <<"height" + std::to_string(idx) << height <<"width" + std::to_string(idx) << width <<"size" + std::to_string(idx) << size <<"roundness" + std::to_string(idx) << roundness <<"type" + std::to_string(idx) << type <<"judge" + std::to_string(idx) << judge <<"bounding_x" + std::to_string(idx) << bounding.x() <<"bounding_y" + std::to_string(idx) << bounding.y() <<"bounding_width" + std::to_string(idx) << bounding.width() <<"bounding_height" + std::to_string(idx) << bounding.height() <<"visible" + std::to_string(idx) << visible <<"skip" + std::to_string(idx) << skip <<"inspect_type" + std::to_string(idx) << inspect_type <<"flag" << flag;doc << bsoncxx::builder::stream::close_document;return false;
}bool tpoDie::write_to_database(bsoncxx::builder::stream::document& doc, int idx)
{doc << "die_info" + std::to_string(idx) <<bsoncxx::builder::stream::open_document<<"die_x" + std::to_string(idx) << die_x <<"die_y" + std::to_string(idx) << die_y <<"die_width" + std::to_string(idx) << die_width <<"die_height" + std::to_string(idx) << die_height <<"die_type" + std::to_string(idx) << die_type <<"die_model" + std::to_string(idx) << die_model <<"die_id" + std::to_string(idx) << die_id.toStdString();for (int i = 0; i < InspectedDefect.size(); i++){InspectedDefect[i]->write_to_database(doc, i);     }doc << bsoncxx::builder::stream::close_document;return true;
}

对每个数据结构写一个write document的方法,最后只需要调用wafer的write_to_database方法就能把wafer的每个die的详细信息记录到表中,包括每个die中的缺陷详细信息。

写到数据库中的数据结构是这样的,结构一目了然,wafer中带着die的信息和自身的一些详细信息,die中又有defect的详细信息。

而且这个数据库查询效率奇高,实测千万级的数据,添加了索引之后能在0.1秒之内查询到结果。

http://www.lryc.cn/news/499753.html

相关文章:

  • draggable插件——实现元素的拖动排序——拖动和不可拖动的两种情况处理
  • Redux的使用
  • 【JAVA】Java高级:多数据源管理与Sharding:数据分片(Sharding)技术的实现与实践
  • ASP.NET Core 9.0 静态资产传递优化 (MapStaticAssets )
  • LeetCode刷题day18——贪心
  • MATLAB Simulink® - 智能分拣系统
  • linuxCNC(五)HAL驱动的指令介绍
  • STM32 进阶 定时器3 通用定时器 案例2:测量PWM的频率/周期
  • 第一节、电路连接【51单片机-TB6600驱动器-步进电机教程】
  • 【通俗理解】Koopman算符与非线性动力系统分析
  • mybatis plus打印sql日志
  • ObjectMapper
  • 新增白名单赋予应用安装权限
  • 传奇996_51——脱下装备,附加属性设为0
  • 【Mac】安装Gradle
  • MySQL中的redoLog
  • Windows 安装 MySQL
  • yocto的xxx.bb文件在什么时候会拷贝文件到build目录
  • Ubuntu Server 22.04.5 LTS重启后IP被重置问题
  • Java基础复习
  • 简易图书管理系统
  • 结构型-组合模式(Composite Pattern)
  • 【知识堂】大数据
  • 力扣C语言刷题记录(三)搜索插入位置
  • 在Node.js局域网调试https的Vue项目
  • 3.5 认识决策树
  • 股市复盘笔记
  • Canal 深入解析:从原理到实践的全面解读
  • SQL SERVER 2016 AlwaysOn 无域集群+负载均衡搭建与简测
  • 解决 Maven 部署中的 Artifact 覆盖问题:实战经验分享20241204