- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在为一家出租公寓的公司创建系统。所有定价设置都基于某些时期。例如,“小型单间公寓”类别中的公寓有价格周期:
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/
我需要一些帮助。 我希望“总计”由“数量*价格=总计”计算(到目前为止没问题)。问题是我还需要通过“总/价格=数量”来计算“数量”,即如果一个字段发生更改,另一个字段也会自动更改。 我做了一个非常简单
我试图将每件商品的数量和价格相乘来计算总数,但我的警报中出现错误。 $.each(data.items, function(index, d){ var calcultest = d.pric
我想获得格式化的价格但没有货币符号,我只想使用 magento 的标准功能! $product->getFinalPrice(); => 19.9900 Mage::helper('core')->f
我正在尝试获取特定月份和年份中所有父类别的总价格。父类别是 parent_id == 0 的任何类别。我的查询如下所示: SELECT ROUND(SUM(od.total_price)) a
请帮我摆脱我的头痛..提前我为我的糟糕语言道歉,无论是英语还是mysql。希望有人能理解这个问题..:) 我有一个数据库,任何人都可以记录各个商店中各种产品的价格。以下查询是一个半理论示例,可能根本不
下面是我需要在数据库中设计的示例: 会有一个价格选项,如果有的话,会有一个特价选项,然后我想知道如果我希望其中一个选项是“免费”的,我该怎么做。 另请参阅根据所在国家/地区会有不同的货币。这是我的想法
商品价格格式 999,99 999 - 1 ..4 digits , - comma sign marks decimal point 99 - 2 digits after price Postg
我有这个表 stk +---------+--------------+ | Field | Type | +---------+--------------+ | id
是否有一个简单的格式化程序可以将我的字符串格式化为价格? 所以我的字符串是:300000 我想用空格来“300 000” or 1000000 "1 000 000" 张国荣 最佳答案 这样做: St
我想知道是否可以使用不依赖于 Excel 应用程序本地化(欧盟/美国)的 Excel 公式来自定义数字格式? 例如,我的值为 1291660。 然后使用公式=TEXT(A1;"# ##0,00") .
这是我的代码,对于价格 slider : $("#price-slider").ionRangeSlider({ min: 130, max: 575, onChange :
用户可以使用价格创建一个新实体。价格可以使用不同的货币(EUR,USD ...),因此我们可以乘以(price * convert_rate)得到实际价格。 我想做的是根据价格过滤记录,具体取决于前端
我正在尝试隐藏小数位在类型输入字段上,例如 数字从0.00开始 因此,输入字段中的第一个位置将为 0.00 我输入的1比它应该变成0.01 我输入的2比它应该变成0.12 比 0 所以它应该变成 1.
$res=mysql_query($qry); while($row= mysql_fetch_array($res)) { echo "".$row['Food_Name']." ".$row['P
我们正在为我们的新项目寻找信用卡网关。那里一片困惑,所有人都想把你切成碎片。每次我与他们交谈时,他们都有不同的费率,每次更新报价时,他们都会更改一些价格。 我们正在使用 .net、C#、asp.net
我已经创建了一个 jQuery 价格 slider ,但我不确定如何让过滤区域以实际价格范围开始?目前它有“$[object Object] - $[object Object]”,而我希望它有“$2
我已经创建了 jquery 价格 slider ,但我不确定如何过滤我的结果,以便在滑动时您只能看到具有该值范围内的产品。 HTML: Price range:
我有一个页面,其中有一个表格,我们可以在其中选择一个产品,输入它的数量和价格,然后应在最后一列中计算金额,并应添加新行以输入更多产品,直到我们完成为止。
我创建了电子商务网站,即将提供午餐和晚餐服务。我在这里提出问题/问题是因为我知道这里有很多可以帮助我的传奇人物。我在网站上添加了套餐/计划部分。 1. Weekly 2. Monthly 以下是订
我的网站需要一个简单的 jQuery 价格 slider 。从 0 英镑到 1000 英镑不等。 假设浏览器将 slider 设置为 100 英镑(例如),然后我需要一个立即购买按钮,该按钮将 sli
我是一名优秀的程序员,十分优秀!