| | 186 | |
| | 187 | === Relational Algebra === |
| | 188 | |
| | 189 | Selecting recent inquiries and joining to client and unit: |
| | 190 | |
| | 191 | {{{ |
| | 192 | RecentInquiries ← σ(created_at ≥ CURRENT_DATE − 180)(Inquiry) |
| | 193 | |
| | 194 | InquiryClientUnit ← RecentInquiries |
| | 195 | ⋈(inquiry.client_id = client.client_id) Client |
| | 196 | ⋈(inquiry.unit_id = unit.unit_id) Unit |
| | 197 | }}} |
| | 198 | |
| | 199 | Aggregating per client — inquiry-side statistics: |
| | 200 | |
| | 201 | {{{ |
| | 202 | ClientInquiryStats ← γ( |
| | 203 | client_id, name, email, phone ; |
| | 204 | COUNT(inquiry_id) → total_inquiries, |
| | 205 | MIN(created_at) → first_inquiry_date, |
| | 206 | MAX(created_at) → last_inquiry_date, |
| | 207 | AVG(price) → avg_inquired_price |
| | 208 | )(InquiryClientUnit) |
| | 209 | }}} |
| | 210 | |
| | 211 | Selecting recent appointments and joining to timeslot: |
| | 212 | |
| | 213 | {{{ |
| | 214 | RecentAppts ← σ(timeslot.date ≥ CURRENT_DATE − 180)( |
| | 215 | Appointment ⋈(appointment.timeslot_id = timeslot.timeslot_id) Timeslot |
| | 216 | ) |
| | 217 | }}} |
| | 218 | |
| | 219 | Aggregating per client — appointment-side statistics: |
| | 220 | |
| | 221 | {{{ |
| | 222 | ClientApptStats ← γ( |
| | 223 | client_id ; |
| | 224 | COUNT(appointment_id) → total_appointments, |
| | 225 | MIN(timeslot.date) → first_appointment_date |
| | 226 | )(RecentAppts) |
| | 227 | }}} |
| | 228 | |
| | 229 | Left joining, deriving interest classification and ranking: |
| | 230 | |
| | 231 | {{{ |
| | 232 | Combined ← ClientInquiryStats ⟕(client_id = client_id) ClientApptStats |
| | 233 | |
| | 234 | WithScore ← ρ( |
| | 235 | interest ← IF(total_appointments > 0, 'Warm Interest', 'Cold Interest'), |
| | 236 | engagement_rank ← RANK() OVER ( |
| | 237 | ORDER BY (total_inquiries + total_appointments · 3) DESC |
| | 238 | ) |
| | 239 | )(Combined) |
| | 240 | |
| | 241 | Result ← τ(engagement_rank)(WithScore) |
| | 242 | |
| | 243 | π(engagement_rank, name, email, phone, |
| | 244 | interest, total_inquiries, total_appointments, |
| | 245 | days_to_first_appointment, avg_inquired_price, |
| | 246 | first_inquiry_date, last_inquiry_date)(Result) |
| | 247 | }}} |