You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.3 KiB

  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. using System.Linq;
  5. namespace Sevomin.Models
  6. {
  7. public class DovominJob
  8. {
  9. [Key]
  10. public long Id { get; set; }
  11. [Index("IX_DovominJobUniqueIndex", Order = 1, IsUnique = true)]
  12. [Required]
  13. [StringLength(128)]
  14. public string DovominId { get; set; }
  15. [Index]
  16. [Index("IX_DovominJobUniqueIndex", Order = 2, IsUnique = true)]
  17. [Required]
  18. public long JobId { get; set; }
  19. [Required]
  20. public DateTime ApplyDate { get; set; }
  21. public string CoverLetter { get; set; }
  22. public decimal Affinity { get; set; }
  23. public bool MinimumRequirement { get; set; }
  24. public DateTime? AvalinSeen { get; set; }
  25. public string AvalinComment { get; set; }
  26. public bool AvalinDelete { get; set; }
  27. public virtual Dovomin Dovomin { get; set; }
  28. public virtual Job Job { get; set; }
  29. public DovominJob(Dovomin dovomin, Job job)
  30. {
  31. this.Dovomin = dovomin;
  32. this.Job = job;
  33. CalculateAffinity();
  34. }
  35. public DovominJob()
  36. {
  37. }
  38. public void CalculateAffinity()
  39. {
  40. if (Dovomin == null || Job == null)
  41. return;
  42. MinimumRequirement = true;
  43. decimal sum = 0;
  44. decimal count = 0;
  45. decimal maxPoint = 0;
  46. Affinity = 0;
  47. foreach (var jp in
  48. Job.JobParameters.Where(x=>x.Moscow != 0 && !string.IsNullOrWhiteSpace(x.StringValue) ))
  49. {
  50. count++;
  51. decimal m = jp.Moscow - 1 ;
  52. maxPoint += jp.Parameter.BasePoint * m;
  53. DovominParameter dp = Dovomin.DovominParameters.SingleOrDefault(x=>x.ParameterId == jp.ParameterId);
  54. if (dp == null)
  55. continue;
  56. if (jp.Moscow == 4)
  57. {
  58. if ((jp.StringValue != dp.StringValue && jp.NumericValue == 0)
  59. || (jp.NumericValue > 0 && jp.NumericValue > dp.NumericValue))
  60. {
  61. MinimumRequirement = false;
  62. }
  63. }
  64. decimal? dpv = dp.NumericValue;
  65. decimal? jpv = jp.NumericValue;
  66. if (jpv == null)
  67. {
  68. if (jp.StringValue == dp.StringValue)
  69. sum += m * jp.Parameter.BasePoint;
  70. continue;
  71. }
  72. if (dpv == null)
  73. continue;
  74. if (jpv <= dpv)
  75. sum += m * jp.Parameter.BasePoint;
  76. //v2
  77. //if (jpv <= dpv)
  78. // sum += m;
  79. //else
  80. // sum += m * ((jpv.Value - dpv.Value) / (jpv.Value == 0 ? (decimal)0.000001 : jpv.Value));
  81. }
  82. if (maxPoint == 0)
  83. this.Affinity = 100;
  84. this.Affinity = Math.Round( sum / maxPoint, 2, MidpointRounding.ToEven) * 100;
  85. }
  86. }
  87. }