Skip to content

Instantly share code, notes, and snippets.

module ForecastGenerator
class Seasoned
attr_reader :data, :data_trend, :forecast
def initialize(data)
@data = data
@coeffs = get_coefficients
@trend_params = trend_params
@data_trend = trend(@data.count)
require "csv"
class ForecastCSV < Struct.new(:forecast, :current_user_id)
def perform
data = forecast.detect{|f| f[:name] == 'forecast'}[:data]
path = "tmp/Forecast-#{Time.now.strftime("%d-%m-%Y %I:%M-%S")}.csv"
CSV.open(path, "w+") do |csv|
csv << ["date", "value"]
class LinearRegression
def initialize(hash)
x = hash.keys
y = hash.values
@xs, @ys = x, y
if @xs.length != @ys.length
raise "Unbalanced data. xs need to be same length as ys"
end
end
class ForecastsController < ApplicationController
include ForecastsHelper
layout 'forecasts'
before_action :set_dates, :set_chart_data, only: [:index, :table]
def index
respond_to do |format|
format.html
format.csv {
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= title %></title>
<meta name="description" content="<%= content_for?(:description) ? yield(:description) : "Sail CRM" %>">
<%= favicon_link_tag %>
<%= javascript_include_tag 'forecasts' %>
<%= stylesheet_link_tag 'forecasts', media: 'all' %>
= form_tag forecasts_path, method: :get do
.row.forecast-row.flex-container.space-between
.forecast-bar
.title
| Use data since:
= text_field_tag :data_start, @data_dates.first, class: 'form-control'
.forecast-bar
.title
| Cruise
SELECT p.id, par.first_name ||' '|| par.last_name AS partners_name,
c.first_name ||' '|| c.last_name AS customers_name,
en_c.first_name ||' '|| en_c.last_name AS enquiry_customers_name,
coalesce(par.first_name||par.last_name, c.first_name||c.last_name, en_c.first_name||en_c.last_name, 'test') AS result
FROM passengers p
LEFT JOIN customers c ON p.customer_id = c.id
LEFT JOIN partners par ON p.partner_id = par.id
JOIN enquiries e ON p.enquiry_id = e.id
JOIN customers en_c ON e.customer_id = en_c.id
ORDER BY coalesce(par.first_name||' '||par.last_name, c.first_name||' '||c.last_name, en_c.first_name||' '||en_c.last_name)
def extras_total
@extras_total ||= extras.reject(&:_destroy).sum(&:amount)
end
- 4
- 8h fixing tour's import (TOURS IMPORT)
- 1h (investigating missing Representatives)
- 5
- 3h added the new search option, refactored API (add search by a boat for api)
- 2h (fixing empty cells in the enquiry report)
- 3h (add bcc to all outgoing emails)
- 6
- 3h deploy and test some tasks with Justin, some work with payments (manage and check)
- 2h investigate and find a new js lib for the button (fix copy button)
def update
respond_to do |format|
if @enquiry.update(enquiry_params)
cust = @enquiry.customer
cust.title=params[:enquiry][:customer][:title] if params[:enquiry][:customer][:title].present?
cust.first_name=params[:enquiry][:customer][:first_name] if params[:enquiry][:customer][:first_name].present?
cust.last_name=params[:enquiry][:customer][:last_name] if params[:enquiry][:customer][:last_name].present?
cust.address=params[:enquiry][:customer][:address] if params[:enquiry][:customer][:address].present?
cust.age=params[:enquiry][:customer][:age] if params[:enquiry][:customer][:age].present?
cust.nationality=params[:enquiry][:customer][:nationality] if params[:enquiry][:customer][:nationality].present?