openreplay/mobs/run.rb
MauricioGarciaS 91921d622e
fix(connectors): Created module in Cython to speed up message decoding (#1338)
* Updated pg connector

* fix(player): fix first 8 byte checker

* fix(player): fix commit conflict

* Added pylint

* Removed pylint for incompatible license

* change(ui): check for sessions records state

* Patch/api v1.12.0 (#1299)

* fix(chalice): include metadata in sessions exp search

* fix(chalice): fixed sessions exp search wrong col name

* fix(chalice): removed cookies

* fix(chalice): changed base image to support SSO/xmlsec

* fix(chalice): changed Dockerfile to support SSO/xmlsec

* fix(chalice): changed Dockerfile to support SSO/xmlsec

(cherry picked from commit 4b8cf9742c)

* fix(ui): project fallback to recorded variable

* Patch/api v1.12.0 (#1301)

* fix(chalice): changed base image to support SSO/xmlsec

* fix(chalice): fixed exp search null metadata

(cherry picked from commit ab000751d2)

* change(ui): assist no content message styles and icons

* change(ui): revert menu disable

* fix(connector): Added method to save state in s3 for redshift if sigterm arise

* Rewriting python code in cython

* Added pyx module for messages

* Auto create pyx files

* Updated and fixed msgcodec.pyx

* Added new module to connector code

* Updated kafka lib for base image

* cleaned Docker and updated base image version for pandas

* cleaned prints

* Added code to fetch data from db and add it into redshift

* Updated consumer reading method. Async multithreading over sessionId

* Added split for country (Country,State,City)

* Fixed decoding issue for uint

* Created service able to fix data from redshift by reading from db

* Handle when process ended because of lost connection to pg, country set to country value only
2023-06-23 14:49:39 +02:00

152 lines
2.8 KiB
Ruby

require 'erb'
# TODO: change method names to correct (CapitalCase and camelCase, not CamalCase and firstLower)
class String
def upperize_abbreviations
self.sub('Id', 'ID').sub('Url', 'URL')
end
# PascalCase
def pascal_case
return self if self !~ /_/ && self =~ /[A-Z]+.*/
split('_').map{|e| e.capitalize}.join.upperize_abbreviations
end
# camelCase
def camel_case
self.sub(/^[A-Z]+/) {|f| f.downcase }
end
# snake_case
def snake_case
self.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
tr("-", "_").
downcase
end
end
class Attribute
attr_reader :name, :type
def initialize(name:, type:)
@name = name
@type = type
end
def type_js
case @type
when :int
"number"
when :uint
"number"
when :json
# TODO
# raise "Unexpected attribute type: data type attribute #{@name} found in JS template"
"string"
when :data
raise "Unexpected attribute type: data type attribute #{@name} found in JS template"
else
@type
end
end
def type_go
case @type
when :int
'int64'
when :uint
'uint64'
when :string
'string'
when :data
'[]byte'
when :boolean
'bool'
when :json
'interface{}'
end
end
def type_pyx
case @type
when :int
'long'
when :uint
'unsigned long'
when :string
'str'
when :data
'str'
when :boolean
'bint'
when :json
'str'
end
end
def lengh_encoded
case @type
when :string, :data
true
else
false
end
end
end
$context = :web
class Message
attr_reader :id, :name, :tracker, :replayer, :swift, :attributes, :context
def initialize(name:, id:, tracker: $context == :web, replayer: $context == :web, swift: $context == :ios, &block)
@id = id
@name = name
@tracker = tracker
@replayer = replayer
@swift = swift
@context = $context
@attributes = []
# opts.each { |key, value| send "#{key}=", value }
instance_eval &block
end
%i(int uint boolean string data).each do |type|
define_method type do |name, opts = {}|
opts.merge!(
name: name,
type: type,
)
@attributes << Attribute.new(opts)
end
end
end
$ids = []
$messages = []
def message(id, name, opts = {}, &block)
raise "id duplicated #{name}" if $ids.include? id
$ids << id
opts[:id] = id
opts[:name] = name
msg = Message.new(opts, &block)
$messages << msg
end
require './messages.rb'
$context = :ios
require './ios_messages.rb'
Dir["templates/*.erb"].each do |tpl|
e = ERB.new(File.read(tpl))
path = tpl.split '/'
t = '../' + path[1].gsub('~', '/')
t = t[0..-5]
# TODO: .gen subextention
File.write(t, e.result)
puts tpl + ' --> ' + t
end