gpt4 book ai didi

基于周期的价格计算算法

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:53:25 26 4
gpt4 key购买 nike

我正在为一家出租公寓的公司创建系统。所有定价设置都基于某些时期。例如,“小型单间公寓”类别中的公寓有价格周期:

30.05.2016 - 31.01.2017: 3000 EUR
01.02.2017 - Infinity: 4000 EUR

还有其他时期,例如:税收、季节性价格(加/减某个百分比值)和基于其他时期的费用。因此价格可能经常变化,例如:

31.05.2016 - 30.06.2016 (3500EUR because of some seasonal price period)
01.07-31.08.2016 (5000EUR other seasonal price period)
01.09.2016 - 31.01.2017 (3000 EUR)
01.02.2017 - 4000 EUR.

此外,如果有人想租一间公寓,例如少于 15 天,则需要支付额外费用,比如说 15% - 所有这些都是动态设置的。

现在问题出在我们的页面上,我们应该让用户根据价格找到公寓。例如,一些用户只想找到价格在 3000 - 4000 欧元之间的公寓,并租用公寓 6 个月。正如我所说,在这些时期价格可能会发生变化,例如 5 次,因此我希望计算平均价格。

您知道如何实现此算法以合并所有指定时间段吗?我们假设可能有 500 条记录,因此动态计算可能会导致性能问题。

更新

下面是一些代码,用于获取与一栋建筑的一个公寓类别相关的期间:

private RentPriceAggregatedPeriodsDto prepareRentPriceAggregator(Long buildingId, Long categoryId, LocalDate dateFrom, LocalDate dateTo, Integer duration) {
List<CategoryPricePeriod> pricePeriods = categoryPricePeriodRepository.findCategoryPricePeriods(buildingId, categoryId, dateFrom, dateTo);
List<SeasonalPricePeriod> seasonalPricePeriods = seasonalPricePeriodRepository.findSeasonalPricePeriods(buildingId, categoryId, dateFrom, dateTo);
List<LastMinuteRatePeriod> lastMinuteRatePeriods = lastMinuteRatePeriodRepository.findLastMinuteRatePeriods(buildingId, categoryId, dateFrom, dateTo);
List<TaxesDefinitionPeriodDto> taxesDefinition = taxesDefinitionService.findTaxPeriodsForBuildingAndCategory(buildingId, categoryId, TaxTypeCode.VAT,
dateFrom, dateTo);
Optional<SurchargePolicy> surcharge = surchargePolicyRepository.findForDurationAndRentalObjectCategoryIds(categoryId, buildingId, duration);

return new RentPriceAggregatedPeriodsDto(pricePeriods, seasonalPricePeriods, lastMinuteRatePeriods, taxesDefinition, surcharge);
}

根据所有这些周期,我准备了独特价格周期的列表:dateFrom、dateTo、currency、value。在这些步骤之后,我有一个类别的唯一价格列表。然后我需要计算每个独特价格周期的预订天数并将其相乘,也许四舍五入 + 乘以税金并将其相加得到最终预订价格。现在重新运行这些步骤,比方说,500 次(多个建筑物中的多个类别)。

最佳答案

如评论中所述,对 6 个数字进行平均 500 次应该不会导致任何性能问题。

即便如此,如果您希望在价格计算上达到 O(1) 性能(即计算不应该依赖于上述期间内价格切换的次数),您可以通过以下方式进行预处理将日期定义为第 0 天,并计算超过该天的所有天数所需的总租金数额。当用户请求一个时期之间的平均租金时,从两天中减去到第 0 天的总租金,得到这两个时期之间的租金。将其除以天数将得出平均租金。您还可以根据停留时间添加合适的乘数(以添加 15% 的费用)等。这类似于在 O(1) 中查找数组中两个索引之间的值之和。这不是一个内存友好的建议,尽管可以修改它以使用更少的内存。

优点是给出结果的计算不依赖于价格转换的次数。然而,公寓租金的每一次额外变化都会导致一些预处理。

关于基于周期的价格计算算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44258499/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com