Skip to content

Logic for calculating ProjectEstimationItems

vikasrohit edited this page Aug 23, 2019 · 6 revisions

The initial task is described in the next issue and implemented by the next PR.

Calculate estimation items using BuildingBlocks

When we create a project with estimations we are trying to find buildingBlocks for that estimations. If we found them and they have privateConfig with defined priceItems then we for such estimation we create estimation items.

Example:
  • We have an estimation during project creation:

    {
      id: 7,
      buildingBlockKey: 'BLOCK_KEY',
      price: 6000
    }

    And we found a buildingBlock for such estimation:

      id: 13,
      key: 'BLOCK_KEY',
      privateConfig: {
        priceItems: {
          community: 3456,
          topcoder_service: '20%',
          fee: 1234
        }
      }

    Than 3 estimation item records would be created:

    [
      { price: 3456, type: 'community', projectEstimationId: 7, markupUsedReference: 'buildingBlock', markupUsedReferenceId: 13 },
      { price: 1200, type: 'topcoder_service', projectEstimationId: 7, markupUsedReference: 'buildingBlock', markupUsedReferenceId: 13 },
      { price: 1234, type: 'fee', projectEstimationId: 7, markupUsedReference: 'buildingBlock', markupUsedReferenceId: 13 }
    ]
Notes:
  • calculation using buildingBlocks would happened only once during project creation. As project is just created, so we just create new one and we don't have to remove existent ones, as there are no existent estimation items for a new project.
  • we don't have any logic to recalculate price estimation on using buildingBlocks. Candiate events to do so in the future:
    • when we change the project scope. So far we don't update estimations records when we update project scope, thus we don't recalculate estimations items also
    • when we change buildingBlocks records. Not sure if project estimation items should be recalculated or no in such case. Though so far we don't have any API to mange buildingBlocks thus we don't have any events to recalculate estimation items. Note, putting such logic may trigger recalculation estimation items for multiple projects

Calculate estimation items using ProjectSettings

When we have already created project we can added ProjectSettings for it, using ProjectSettings CRUD API. ProjectSettings may contain any kind of settings, but this functionality we are only interested in ProjectSettings which are related to price estimation breakdown, such ProjectSettings have keys in the next format: markup_<estimation_item_type>, for example markup_community or markup_topcoder_service. Every time when we add, update or delete ProjectSettings which are related to price breakdown (the ones with key like markup_<estimation_item_type>) we do 2 things:

  1. Remove all existent estimation items for the project. It means that we would remove estimation items which were created during project creation using buildingBlocks. Also, it would remove any estimation items which were previously created using ProjectSettings.
  2. Create new estimation items for the project based on all current ProjectSettings. This means that if we have several estimation items based on ProjectSettings and we changed just one, or added a new one we would re-create ALL existent estimation items even though they are not changed.
Example:
  • Project has one ProjectEstimation record:

    {
      id: 7,
      buildingBlockKey: 'BLOCK_KEY',
      price: 6000
    }

    We created several ProjectSettings:

    {
      "id": 1,
      "key": "markup_community"
      "value": "3000",
      "valueType": "double",
    },
    {
      "id": 2,
      "key": "markup_topcoder_service"
      "value": "10",
      "valueType": "percentage",
    }, 
    {
      "id": 3,
      "key": "markup_fee"
      "value": "1000",
      "valueType": "double",
    },

    Than 3 estimation item records would be created:

    [
      { price: 3000, type: 'community', projectEstimationId: 7, markupUsedReference: 'projectSetting', markupUsedReferenceId: 1 },
      { price: 600, type: 'topcoder_service', projectEstimationId: 7, markupUsedReference: 'projectSetting', markupUsedReferenceId: 2 },
      { price: 1000, type: 'fee', projectEstimationId: 7, markupUsedReference: 'projectSetting', markupUsedReferenceId: 3 }
    ]

Notes

As results of the logic above.

  • Estimation items for one project would be always created either using BuildingBlocks or ProjectSettings, but not together.
  • ProjectSettings have higher priority than BuildingBlocks. So if there is at least one ProjectSetting for price estimation for a project (which means this logic works only for existing projects because we can not have setting for a non existing project), than all existent estimation items based on BuildingBlocks would be removed, and new one based on ProjectSettings would be created.
  • In other words, project estimation items would be created using BuildingBlocks for a new project, however, for an existing project if there exists at least one price estimation setting in ProjectSettings for the project, estimation items would be recreated using the settings route and previous estimation items would be discarded.