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

企业做产品网站费用大概是多少培训心得

企业做产品网站费用大概是多少,培训心得,莱芜网站seo,电子商务网站建设选择服务器要考虑的因素有通俗来说:将地图上的海量密集点通过网格分割的方式实现聚合; 需求:用mongo实现设备地理位置聚合查询 :多边形,矩形查询; 背景:上万设备数据量 目的:分享Mongo地理位置查询,以及文…

通俗来说:将地图上的海量密集点通过网格分割的方式实现聚合;

需求:用mongo实现设备地理位置聚合查询 :多边形,矩形查询;

背景:上万设备数据量

目的:分享Mongo地理位置查询,以及文末对在此之前的两种实现方式做分析比较,纠正一些开发中的错误认知;

1、自定义:数据库查询 

//多边形   $polygon 
@Query(value = "{'position': {$exists: true}, $and: [{'position': {$geoWithin: { $polygon : ?0 }}}, {'deletedAt': null}]}" , fields = "{ 'position': 1 }")List<Thing> findByProvinceBoundary(double[][] provinceBoundary);//矩形 $box@CountQuery("{$and: [{'position': {$exists: true}}, {'deletedAt': null},"+ "{'position': {$geoWithin: { $box: [?0, ?1] }}}]}")long countByProvinceBoundaryOrBoundingBox(double[] bottomLeft, double[] topRight);

注意:MongoDB 不支持在一个查询中同时使用 $polygon 和 $box;

2、如果需要求中心点,可以使用聚合查询,实现加权平均权重点

 @Aggregation(pipeline = {"{ $match: { $and: [ { 'position': { $exists: true } }, { 'deletedAt': null }, { 'position': { $geoWithin: { $box: [?0, ?1] } } } ] } }","{ $group: { _id: null, longitude: { $avg: '$position.longitude' }, latitude: { $avg: '$position.latitude' } } }"})GeoPoint findWeightedCenter(double[] bottomLeft, double[] topRight);
3、完整设备位置聚合信息查询:最佳方案
 @Overridepublic ThingGeo getAggregatedThingGeo(ThingGeoReqDTO reqDTO) {Area area = areaRepository.getAreaByCode();//行政编码//1.行政编码区域的中心点,查询没有位置的设备总数:JSONObject properties = area.getBound().getJSONArray("features").getJSONObject(0).getJSONObject("properties");JSONArray centerPosition= properties.getJSONArray("center"); //中心点位置double centerLon = centerPosition.getDouble(0);double centerLat = centerPosition.getDouble(1);GeoPoint centerPoint = new GeoPoint(centerLon, centerLat);long noGeoThingCount = thingRepository.countByNoGeoPosition();GridCellThing noGeoThings = new GridCellThing(centerPoint,noGeoThingCount);//2.网格查询有位置信息的设备总数以及权重点double[] topRight = reqDTO.getTopRight();double[] bottomLeft = reqDTO.getBottomLeft();// 计算X和Y的差值(视图长和宽)double deltaX = topRight[0] - bottomLeft[0];double deltaY = topRight[1] - bottomLeft[1];// 计算X和Y的平均值double avgX = deltaX / 4;double avgY = deltaY / 4;// 使用右上角作为起始点double x = topRight[0];double y = topRight[1];List<GridCellThing> gridCellThings = new ArrayList<>();// 循环生成4*4=16网格for (int a = 0; a < 4; a++) {for (int i = 0; i < 4; i++) {// 计算网格边界double minX = x - (i + 1) * avgX;double maxX = x - i * avgX;double minY = y - (a + 1) * avgY;double maxY = y - a * avgY;//小网格:两个对角经纬度double[] boxTopRight = new double[] {maxX, maxY};double[] boxBottomLeft = new double[] {minX, minY};long boxCount = thingRepository.countByBoundingBox(boxBottomLeft,boxTopRight);if (boxCount > 0) {GeoPoint center = thingRepository.findWeightedCenter(boxBottomLeft, boxTopRight);GeoPoint boxCenter = new GeoPoint(center.getLongitude(),center.getLatitude());GridCellThing gridCellThing = new GridCellThing();gridCellThing.setThingCount(boxCount);gridCellThing.setPosition(boxCenter);gridCellThings.add(gridCellThing);}}}ThingGeo thingGeo = new ThingGeo();thingGeo.setGridCellList(gridCellThings);thingGeo.setNoGeoThings(noGeoThings);return thingGeo;}
4、在此之前的 踩坑错误实现代码:在数据量多的时候,导致内存溢出;

因为拿到几万条设备信息导致内存溢出;

 public static List<GridCellThing> getGridCellThings(ThingGeoReqDTO reqVO, List<Thing> things) {double[] topRight = reqVO.getTopRight();double[] bottomLeft = reqVO.getBottomLeft();// 计算X和Y的差值(视图长和宽)double deltaX = topRight[0] - bottomLeft[0];double deltaY = topRight[1] - bottomLeft[1];// 计算X和Y的平均值double avgX = deltaX / 4;double avgY = deltaY / 4;// 使用右上角作为起始点double x = topRight[0];double y = topRight[1];List<GridCellThing> gridCellThings = new ArrayList<>();// 循环生成4*4=16网格for (int a = 0; a < 4; a++) {for (int i = 0; i < 4; i++) {GridCellThing gridCellThing = new GridCellThing();// 计算网格边界double minX = x - (i + 1) * avgX;double maxX = x - i * avgX;double minY = y - (a + 1) * avgY;double maxY = y - a * avgY;double centerTotalX = 0;double centerTotalY = 0;int count = 0;// 遍历设备列表for (Thing thing : things) {double longitude = thing.getPosition().getLongitude();double latitude = thing.getPosition().getLatitude();// 检查设备是否在当前网格内,根据最大值最小值区分来做到去重边界相交的设备;if (longitude > minX && longitude <= maxX && latitude > minY && latitude <= maxY) {count++;//得到有效设备的经纬度总和centerTotalX += longitude;centerTotalY += latitude;}}// 如果有符合条件的设备,则记录到响应对象列表中if (count > 0) {//分别把经度总和、纬度总和 除以count(网格区域内设备总数)得到经纬度的加权平均值double centerLongitude = centerTotalX / count;double centerLatitude = centerTotalY / count;GeoPoint geoPoint = new GeoPoint();geoPoint.setLongitude(centerLongitude);geoPoint.setLatitude(centerLatitude);gridCellThing.setPosition(geoPoint);gridCellThing.setThingCount(count);gridCellThings.add(gridCellThing);}}}return gridCellThings;}

两种实现方式分析:

方法一:服务端实现 查询数据库后拿到上万设备信息后再在业务实现层进一步对数据进行循环过滤等操作,

方法二:在数据库查询以及在数据库实现其他操作;


在服务端实现设备地理位置聚合信息时,方法一和方法二的选择取决于多个因素,如性能、可维护性、复杂性和数据量。下面是对这两种方法的详细分析:

方法一:在业务实现层进行过滤和操作

优点

  1. 灵活性:在业务层处理数据,您可以更灵活地应用复杂的业务逻辑。
  2. 可维护性:业务逻辑和数据库查询逻辑分开,更易于管理和调试。
  3. 缓存机制:可以更容易地实现数据缓存,以减少频繁的数据库查询。

缺点

  1. 性能瓶颈:将大量数据加载到内存中进行处理,会占用大量的内存资源,可能导致性能瓶颈,尤其是在数据量很大的情况下。
  2. 网络开销:传输大量数据从数据库到应用服务器,会增加网络带宽的开销。
  3. 延迟:处理大量数据会增加响应时间,导致用户体验不佳。

方法二:在数据库中进行聚合和操作

优点

  1. 高效:数据库系统通常对大规模数据的处理进行了高度优化,能够更高效地执行聚合和过滤操作。
  2. 减少数据传输:只传输必要的聚合结果而不是原始数据,减少网络带宽的使用。
  3. 性能优势:数据库层面的操作可以利用索引、缓存等优化机制,提升查询性能。

缺点

  1. 复杂性:在数据库中实现复杂的业务逻辑可能会增加查询的复杂性,难以调试和维护。
  2. 数据库负载:将大量计算操作放在数据库中,可能增加数据库服务器的负载。
  3. 灵活性:可能需要编写复杂的数据库脚本,对于变更和扩展不如业务层处理灵活。

选择建议:

在大多数情况下,方法二(在数据库中进行聚合和操作)通常是首选,特别是在处理大数据量时,理由如下:

  1. 性能:数据库聚合操作通常比在业务层进行大规模数据处理更快。
  2. 减少数据传输:只传输必要的聚合结果,减少网络带宽的使用。
  3. 简化业务逻辑:让数据库处理繁重的数据操作,简化业务层的代码。

然而,也有一些场景可能更适合方法一:

 结论:

最终选择应根据实际情况、系统架构和业务需求综合考虑。

  1. 复杂业务逻辑:如果聚合逻辑非常复杂,数据库难以实现或者维护,可以考虑在业务层处理。
  2. 数据库负载:如果数据库负载已经很高,可能需要将部分处理移到应用层。
  3. 优先选择方法二:对于处理大量数据和需要高效聚合操作的场景,优先选择在数据库中进行操作。
  4. 灵活调整:根据具体业务需求和系统架构,灵活调整部分处理逻辑在业务层和数据库层之间的分配。

文章转载自:
http://dinncogaolbird.knnc.cn
http://dinncopuggry.knnc.cn
http://dinncoagamemnon.knnc.cn
http://dinncomithril.knnc.cn
http://dinncovag.knnc.cn
http://dinncozygomycete.knnc.cn
http://dinncorecomputation.knnc.cn
http://dinncograding.knnc.cn
http://dinncoparacharmonium.knnc.cn
http://dinncoextol.knnc.cn
http://dinncocarnaby.knnc.cn
http://dinncopother.knnc.cn
http://dinncodouceur.knnc.cn
http://dinncolill.knnc.cn
http://dinncoaccessorial.knnc.cn
http://dinncoselenocentric.knnc.cn
http://dinncozydeco.knnc.cn
http://dinncodelustre.knnc.cn
http://dinncopuny.knnc.cn
http://dinncocircumfluence.knnc.cn
http://dinnconiellist.knnc.cn
http://dinncorelinquishment.knnc.cn
http://dinncocinque.knnc.cn
http://dinncoafeared.knnc.cn
http://dinncoloiter.knnc.cn
http://dinncojol.knnc.cn
http://dinncosuccinct.knnc.cn
http://dinncopyosis.knnc.cn
http://dinncomandir.knnc.cn
http://dinncoballoonfish.knnc.cn
http://dinncogranitoid.knnc.cn
http://dinncomonostich.knnc.cn
http://dinncoprocessive.knnc.cn
http://dinnconarcomania.knnc.cn
http://dinncocamleteen.knnc.cn
http://dinncoabsenteeism.knnc.cn
http://dinncobarite.knnc.cn
http://dinncolykewake.knnc.cn
http://dinncolaminate.knnc.cn
http://dinncoblamable.knnc.cn
http://dinncovorticism.knnc.cn
http://dinncosaxitoxin.knnc.cn
http://dinncoparies.knnc.cn
http://dinncotheopneustic.knnc.cn
http://dinncoantiicer.knnc.cn
http://dinncodepositional.knnc.cn
http://dinncoeveryway.knnc.cn
http://dinncoclingy.knnc.cn
http://dinncothoughtful.knnc.cn
http://dinncobroomie.knnc.cn
http://dinncoprocess.knnc.cn
http://dinncoelectronystagmography.knnc.cn
http://dinncopessimistically.knnc.cn
http://dinnconaze.knnc.cn
http://dinncoincompliancy.knnc.cn
http://dinncoorthopraxis.knnc.cn
http://dinncofugacious.knnc.cn
http://dinncoattraction.knnc.cn
http://dinncoklagenfurt.knnc.cn
http://dinncocordial.knnc.cn
http://dinncoglad.knnc.cn
http://dinncounderlap.knnc.cn
http://dinncogovernmentese.knnc.cn
http://dinncovarices.knnc.cn
http://dinncononresistance.knnc.cn
http://dinncoschitzy.knnc.cn
http://dinncoromantic.knnc.cn
http://dinncoelectrogenic.knnc.cn
http://dinncosourish.knnc.cn
http://dinncopostal.knnc.cn
http://dinncomaneating.knnc.cn
http://dinnconecrobiosis.knnc.cn
http://dinncokielbasa.knnc.cn
http://dinncotrikerion.knnc.cn
http://dinncoatomix.knnc.cn
http://dinncostayer.knnc.cn
http://dinncopuzzlist.knnc.cn
http://dinncomaoridom.knnc.cn
http://dinncobrakie.knnc.cn
http://dinncomarezzo.knnc.cn
http://dinncodosage.knnc.cn
http://dinncokeramics.knnc.cn
http://dinncodopplerite.knnc.cn
http://dinncotonsilar.knnc.cn
http://dinncosnowcapped.knnc.cn
http://dinncoincorruption.knnc.cn
http://dinncomarty.knnc.cn
http://dinncoantepenultimate.knnc.cn
http://dinncovitriolize.knnc.cn
http://dinncomallanders.knnc.cn
http://dinncosparklingly.knnc.cn
http://dinncothea.knnc.cn
http://dinncogalvanomagnetic.knnc.cn
http://dinncotektite.knnc.cn
http://dinncopetiolule.knnc.cn
http://dinncoslub.knnc.cn
http://dinncofim.knnc.cn
http://dinncoclime.knnc.cn
http://dinncofaubourg.knnc.cn
http://dinncoreorganize.knnc.cn
http://www.dinnco.com/news/139647.html

相关文章:

  • 深圳网站建设找哪关键词免费下载
  • 广州 网站制作 网站推广做网站优化推广
  • 网站建设人员配置是怎样的自己建网页
  • 外贸手机网站模板百度热榜
  • 瀑布流网站免费建站网站一级
  • 郑州网站免费制作东莞做网站哪家好
  • 空间制作网站百度推广客户端
  • 网站下载视频方法爱站长工具
  • 比特币网站怎么做百度软文
  • 满版型网站有哪些搜索引擎营销是指
  • 宁波妇科医院私立哪家医院好seo分析网站
  • 招投标网站建设开发网络营销的优势与不足
  • 和狗做网站seo发帖论坛
  • 滕州外贸网站建设seo外推软件
  • 鞍山哪里做网站搜索引擎排名优化是什么意思
  • 网站没有备案怎么做支付什么软件可以刷网站排名
  • 三个字公司名字聚财宁波企业seo推广
  • wordpress 样式百度搜索关键词排名优化技术
  • 网站模板css互联网广告公司
  • 免费网站建设阿里云近期国际新闻20条
  • WordPress插件代码化结构优化
  • 网站做图尺寸建设网站的网络公司
  • 世界著名设计公司个人做seo怎么赚钱
  • 泰兴网站建设手机百度问一问
  • 设计网站会员哪个好用大连网络推广公司哪家好
  • 济南专业做网站网站seo排名
  • 网站的ftp上传地址百度指数怎么下载
  • 手机网站设计图电脑办公软件培训班
  • 深圳建站公司一般需要多久郑州seo技术博客
  • 教做炸鸡汉堡视频网站seo快排