From 5b2f0ab4939206012950de6c8fef818f22d0dda4 Mon Sep 17 00:00:00 2001 From: Keith Lawrence Date: Thu, 12 Oct 2023 14:22:58 +0100 Subject: [PATCH] Add task to create duplicate datasets with gss codes --- lib/tasks/once_off/convert_snac_to_gss.rake | 43 ++ .../once_off/snac_to_gss_translation.csv | 407 ++++++++++++++++++ 2 files changed, 450 insertions(+) create mode 100644 lib/tasks/once_off/convert_snac_to_gss.rake create mode 100644 lib/tasks/once_off/snac_to_gss_translation.csv diff --git a/lib/tasks/once_off/convert_snac_to_gss.rake b/lib/tasks/once_off/convert_snac_to_gss.rake new file mode 100644 index 00000000..3d2ec467 --- /dev/null +++ b/lib/tasks/once_off/convert_snac_to_gss.rake @@ -0,0 +1,43 @@ +namespace :once_off do + desc "Creates duplicate datasets with GSS codes instead of SNACs for local authority data_sets" + task convert_snac_to_gss: [:environment] do + snac_to_gss_lookup = load_snac_to_gss_lookup + + affected_services.each do |service| + puts("INFO: Updating Service: #{service.slug}") + duplicate = service.active_data_set.duplicate + + duplicate.change_notes += ", then updated by once_off:convert_snac_to_gss task" + duplicate.save! + + duplicate.places.each do |place| + next if already_gss?(place.gss) + + snac = place.gss + gss = snac_to_gss_lookup[snac] + if gss.nil? + puts(" - ERROR: Failed to update SNAC #{snac} for #{service.slug}") + else + place.gss = gss + place.save! + end + end + end + end +end + +def load_snac_to_gss_lookup + lookup_cache = {} + CSV.foreach("lib/tasks/once_off/snac_to_gss_translation.csv") do |row| + lookup_cache[row[0]] = row[1] + end + lookup_cache +end + +def affected_services + Service.where(location_match_type: "local_authority") +end + +def already_gss?(code) + code.length > 4 +end diff --git a/lib/tasks/once_off/snac_to_gss_translation.csv b/lib/tasks/once_off/snac_to_gss_translation.csv new file mode 100644 index 00000000..f210d673 --- /dev/null +++ b/lib/tasks/once_off/snac_to_gss_translation.csv @@ -0,0 +1,407 @@ +snac,gss +11,E06000060 +12,E10000003 +16,E10000006 +17,E10000007 +18,E10000008 +21,E10000011 +22,E10000012 +23,E10000013 +24,E10000014 +26,E10000015 +29,E10000016 +30,E10000017 +31,E10000018 +32,E10000019 +33,E10000020 +34,E10000021 +36,E10000023 +37,E10000024 +38,E10000025 +40,E10000027 +41,E10000028 +42,E10000029 +43,E10000030 +44,E10000031 +45,E10000032 +47,E10000034 +00AA,E09000001 +00AB,E09000002 +00AC,E09000003 +00AD,E09000004 +00AE,E09000005 +00AF,E09000006 +00AG,E09000007 +00AH,E09000008 +00AJ,E09000009 +00AK,E09000010 +00AL,E09000011 +00AM,E09000012 +00AN,E09000013 +00AP,E09000014 +00AQ,E09000015 +00AR,E09000016 +00AS,E09000017 +00AT,E09000018 +00AU,E09000019 +00AW,E09000020 +00AX,E09000021 +00AY,E09000022 +00AZ,E09000023 +00BA,E09000024 +00BB,E09000025 +00BC,E09000026 +00BD,E09000027 +00BE,E09000028 +00BF,E09000029 +00BG,E09000030 +00BH,E09000031 +00BJ,E09000032 +00BK,E09000033 +00BL,E08000001 +00BM,E08000002 +00BN,E08000003 +00BP,E08000004 +00BQ,E08000005 +00BR,E08000006 +00BS,E08000007 +00BT,E08000008 +00BU,E08000009 +00BW,E08000010 +00BX,E08000011 +00BY,E08000012 +00BZ,E08000013 +00CA,E08000014 +00CB,E08000015 +00CC,E08000016 +00CE,E08000017 +00CF,E08000018 +00CG,E08000019 +00CH,E08000037 +00CJ,E08000021 +00CK,E08000022 +00CL,E08000023 +00CM,E08000024 +00CN,E08000025 +00CQ,E08000026 +00CR,E08000027 +00CS,E08000028 +00CT,E08000029 +00CU,E08000030 +00CW,E08000031 +00CX,E08000032 +00CY,E08000033 +00CZ,E08000034 +00DA,E08000035 +00DB,E08000036 +00EB,E06000001 +00EC,E06000002 +00EE,E06000003 +00EF,E06000004 +00EH,E06000005 +00EJ,E06000047 +00EM,E06000057 +00EQ,E06000049 +00ET,E06000006 +00EU,E06000007 +00EW,E06000050 +00EX,E06000008 +00EY,E06000009 +00FA,E06000010 +00FB,E06000011 +00FC,E06000012 +00FD,E06000013 +00FF,E06000014 +00FK,E06000015 +00FN,E06000016 +00FP,E06000017 +00FY,E06000018 +00GA,E06000019 +00GF,E06000020 +00GG,E06000051 +00GL,E06000021 +00HA,E06000022 +00HB,E06000023 +00HC,E06000024 +00HD,E06000025 +00HE,E06000052 +00HF,E06000053 +00HG,E06000026 +00HH,E06000027 +00HN,E06000028 +00HP,E06000029 +00HX,E06000030 +00HY,E06000054 +00JA,E06000031 +00KA,E06000032 +00KB,E06000055 +00KC,E06000056 +00KF,E06000033 +00KG,E06000034 +00LC,E06000035 +00MA,E06000036 +00MB,E06000037 +00MC,E06000038 +00MD,E06000039 +00ME,E06000040 +00MF,E06000041 +00MG,E06000042 +00ML,E06000043 +00MR,E06000044 +00MS,E06000045 +00MW,E06000046 +00NA,W06000001 +00NC,W06000002 +00NE,W06000003 +00NG,W06000004 +00NJ,W06000005 +00NL,W06000006 +00NN,W06000023 +00NQ,W06000008 +00NS,W06000009 +00NU,W06000010 +00NX,W06000011 +00NZ,W06000012 +00PB,W06000013 +00PD,W06000014 +00PF,W06000016 +00PH,W06000024 +00PK,W06000018 +00PL,W06000019 +00PM,W06000020 +00PP,W06000021 +00PR,W06000022 +00PT,W06000015 +00QA,S12000033 +00QB,S12000034 +00QC,S12000041 +00QD,S12000035 +00QE,S12000026 +00QF,S12000005 +00QG,S12000039 +00QH,S12000006 +00QJ,S12000042 +00QK,S12000008 +00QL,S12000045 +00QM,S12000010 +00QN,S12000011 +00QP,S12000036 +00QQ,S12000014 +00QR,S12000015 +00QS,S12000046 +00QT,S12000017 +00QU,S12000018 +00QW,S12000019 +00QX,S12000020 +00QY,S12000021 +00QZ,S12000044 +00RA,S12000023 +00RB,S12000024 +00RC,S12000038 +00RD,S12000027 +00RE,S12000028 +00RF,S12000029 +00RG,S12000030 +00RH,S12000040 +00RJ,S12000013 +11UB,E07000004 +11UC,E07000005 +11UE,E07000006 +11UF,E07000007 +12UB,E07000008 +12UC,E07000009 +12UD,E07000010 +12UE,E07000011 +12UG,E07000012 +16UB,E07000026 +16UC,E07000027 +16UD,E07000028 +16UE,E07000029 +16UF,E07000030 +16UG,E07000031 +17UB,E07000032 +17UC,E07000033 +17UD,E07000034 +17UF,E07000035 +17UG,E07000036 +17UH,E07000037 +17UJ,E07000038 +17UK,E07000039 +18UB,E07000040 +18UC,E07000041 +18UD,E07000042 +18UE,E07000043 +18UG,E07000044 +18UH,E07000045 +18UK,E07000046 +18UL,E07000047 +19UC,E07000048 +19UD,E07000049 +19UE,E07000050 +19UG,E07000051 +19UH,E07000052 +19UJ,E07000053 +21UC,E07000061 +21UD,E07000062 +21UF,E07000063 +21UG,E07000064 +21UH,E07000065 +22UB,E07000066 +22UC,E07000067 +22UD,E07000068 +22UE,E07000069 +22UF,E07000070 +22UG,E07000071 +22UH,E07000072 +22UJ,E07000073 +22UK,E07000074 +22UL,E07000075 +22UN,E07000076 +22UQ,E07000077 +23UB,E07000078 +23UC,E07000079 +23UD,E07000080 +23UE,E07000081 +23UF,E07000082 +23UG,E07000083 +24UB,E07000084 +24UC,E07000085 +24UD,E07000086 +24UE,E07000087 +24UF,E07000088 +24UG,E07000089 +24UH,E07000090 +24UJ,E07000091 +24UL,E07000092 +24UN,E07000093 +24UP,E07000094 +26UB,E07000095 +26UC,E07000096 +26UD,E07000242 +26UE,E07000098 +26UF,E07000099 +26UG,E07000240 +26UH,E07000243 +26UJ,E07000102 +26UK,E07000103 +26UL,E07000241 +29UB,E07000105 +29UC,E07000106 +29UD,E07000107 +29UE,E07000108 +29UG,E07000109 +29UH,E07000110 +29UK,E07000111 +29UL,E07000112 +29UM,E07000113 +29UN,E07000114 +29UP,E07000115 +29UQ,E07000116 +30UD,E07000117 +30UE,E07000118 +30UF,E07000119 +30UG,E07000120 +30UH,E07000121 +30UJ,E07000122 +30UK,E07000123 +30UL,E07000124 +30UM,E07000125 +30UN,E07000126 +30UP,E07000127 +30UQ,E07000128 +31UB,E07000129 +31UC,E07000130 +31UD,E07000131 +31UE,E07000132 +31UG,E07000133 +31UH,E07000134 +31UJ,E07000135 +32UB,E07000136 +32UC,E07000137 +32UD,E07000138 +32UE,E07000139 +32UF,E07000140 +32UG,E07000141 +32UH,E07000142 +33UB,E07000143 +33UC,E07000144 +33UD,E07000145 +33UE,E07000146 +33UF,E07000147 +33UG,E07000148 +33UH,E07000149 +34UB,E07000150 +34UC,E07000151 +34UD,E07000152 +34UE,E07000153 +34UF,E07000154 +34UG,E07000155 +34UH,E07000156 +36UB,E07000163 +36UC,E07000164 +36UD,E07000165 +36UE,E07000166 +36UF,E07000167 +36UG,E07000168 +36UH,E07000169 +37UB,E07000170 +37UC,E07000171 +37UD,E07000172 +37UE,E07000173 +37UF,E07000174 +37UG,E07000175 +37UJ,E07000176 +38UB,E07000177 +38UC,E07000178 +38UD,E07000179 +38UE,E07000180 +38UF,E07000181 +40UB,E07000187 +40UC,E07000188 +40UD,E07000189 +40UE,E07000190 +40UF,E07000191 +41UB,E07000192 +41UC,E07000193 +41UD,E07000194 +41UE,E07000195 +41UF,E07000196 +41UG,E07000197 +41UH,E07000198 +41UK,E07000199 +42UB,E07000200 +42UC,E07000201 +42UD,E07000202 +42UE,E07000203 +42UF,E07000204 +42UG,E07000205 +42UH,E07000206 +43UB,E07000207 +43UC,E07000208 +43UD,E07000209 +43UE,E07000210 +43UF,E07000211 +43UG,E07000212 +43UH,E07000213 +43UJ,E07000214 +43UK,E07000215 +43UL,E07000216 +43UM,E07000217 +44UB,E07000218 +44UC,E07000219 +44UD,E07000220 +44UE,E07000221 +44UF,E07000222 +45UB,E07000223 +45UC,E07000224 +45UD,E07000225 +45UE,E07000226 +45UF,E07000227 +45UG,E07000228 +45UH,E07000229 +47UB,E07000234 +47UC,E07000235 +47UD,E07000236 +47UE,E07000237 +47UF,E07000238 +47UG,E07000239 \ No newline at end of file