Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add local evaluation library #11

Merged
merged 2 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ __pycache__/
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
Expand All @@ -14,7 +13,6 @@ dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
Expand Down
15 changes: 15 additions & 0 deletions src/amplitude_experiment/local/evaluation/evaluation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from .libevaluation_interop import libevaluation_interop_symbols


def evaluate(rules: str, user: str) -> str:
"""
Local evaluation wrapper.
Parameters:
rules (str): rules JSON string
user (str): user JSON string

Returns:
Evaluation results with variants in JSON
"""
result = libevaluation_interop_symbols().contents.kotlin.root.evaluate(rules, user)
return str(result, 'utf-8')
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ifndef KONAN_LIBEVALUATION_INTEROP_H
#define KONAN_LIBEVALUATION_INTEROP_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
typedef bool libevaluation_interop_KBoolean;
#else
typedef _Bool libevaluation_interop_KBoolean;
#endif
typedef unsigned short libevaluation_interop_KChar;
typedef signed char libevaluation_interop_KByte;
typedef short libevaluation_interop_KShort;
typedef int libevaluation_interop_KInt;
typedef long long libevaluation_interop_KLong;
typedef unsigned char libevaluation_interop_KUByte;
typedef unsigned short libevaluation_interop_KUShort;
typedef unsigned int libevaluation_interop_KUInt;
typedef unsigned long long libevaluation_interop_KULong;
typedef float libevaluation_interop_KFloat;
typedef double libevaluation_interop_KDouble;
typedef float __attribute__ ((__vector_size__ (16))) libevaluation_interop_KVector128;
typedef void* libevaluation_interop_KNativePtr;
struct libevaluation_interop_KType;
typedef struct libevaluation_interop_KType libevaluation_interop_KType;

typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Byte;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Short;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Int;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Long;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Float;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Double;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Char;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Boolean;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Unit;


typedef struct {
/* Service functions. */
void (*DisposeStablePointer)(libevaluation_interop_KNativePtr ptr);
void (*DisposeString)(const char* string);
libevaluation_interop_KBoolean (*IsInstance)(libevaluation_interop_KNativePtr ref, const libevaluation_interop_KType* type);
libevaluation_interop_kref_kotlin_Byte (*createNullableByte)(libevaluation_interop_KByte);
libevaluation_interop_kref_kotlin_Short (*createNullableShort)(libevaluation_interop_KShort);
libevaluation_interop_kref_kotlin_Int (*createNullableInt)(libevaluation_interop_KInt);
libevaluation_interop_kref_kotlin_Long (*createNullableLong)(libevaluation_interop_KLong);
libevaluation_interop_kref_kotlin_Float (*createNullableFloat)(libevaluation_interop_KFloat);
libevaluation_interop_kref_kotlin_Double (*createNullableDouble)(libevaluation_interop_KDouble);
libevaluation_interop_kref_kotlin_Char (*createNullableChar)(libevaluation_interop_KChar);
libevaluation_interop_kref_kotlin_Boolean (*createNullableBoolean)(libevaluation_interop_KBoolean);
libevaluation_interop_kref_kotlin_Unit (*createNullableUnit)(void);

/* User functions. */
struct {
struct {
const char* (*evaluate)(const char* rules, const char* user);
} root;
} kotlin;
} libevaluation_interop_ExportedSymbols;
extern libevaluation_interop_ExportedSymbols* libevaluation_interop_symbols(void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* KONAN_LIBEVALUATION_INTEROP_H */
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ifndef KONAN_LIBEVALUATION_INTEROP_H
#define KONAN_LIBEVALUATION_INTEROP_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
typedef bool libevaluation_interop_KBoolean;
#else
typedef _Bool libevaluation_interop_KBoolean;
#endif
typedef unsigned short libevaluation_interop_KChar;
typedef signed char libevaluation_interop_KByte;
typedef short libevaluation_interop_KShort;
typedef int libevaluation_interop_KInt;
typedef long long libevaluation_interop_KLong;
typedef unsigned char libevaluation_interop_KUByte;
typedef unsigned short libevaluation_interop_KUShort;
typedef unsigned int libevaluation_interop_KUInt;
typedef unsigned long long libevaluation_interop_KULong;
typedef float libevaluation_interop_KFloat;
typedef double libevaluation_interop_KDouble;
typedef float __attribute__ ((__vector_size__ (16))) libevaluation_interop_KVector128;
typedef void* libevaluation_interop_KNativePtr;
struct libevaluation_interop_KType;
typedef struct libevaluation_interop_KType libevaluation_interop_KType;

typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Byte;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Short;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Int;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Long;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Float;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Double;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Char;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Boolean;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Unit;


typedef struct {
/* Service functions. */
void (*DisposeStablePointer)(libevaluation_interop_KNativePtr ptr);
void (*DisposeString)(const char* string);
libevaluation_interop_KBoolean (*IsInstance)(libevaluation_interop_KNativePtr ref, const libevaluation_interop_KType* type);
libevaluation_interop_kref_kotlin_Byte (*createNullableByte)(libevaluation_interop_KByte);
libevaluation_interop_kref_kotlin_Short (*createNullableShort)(libevaluation_interop_KShort);
libevaluation_interop_kref_kotlin_Int (*createNullableInt)(libevaluation_interop_KInt);
libevaluation_interop_kref_kotlin_Long (*createNullableLong)(libevaluation_interop_KLong);
libevaluation_interop_kref_kotlin_Float (*createNullableFloat)(libevaluation_interop_KFloat);
libevaluation_interop_kref_kotlin_Double (*createNullableDouble)(libevaluation_interop_KDouble);
libevaluation_interop_kref_kotlin_Char (*createNullableChar)(libevaluation_interop_KChar);
libevaluation_interop_kref_kotlin_Boolean (*createNullableBoolean)(libevaluation_interop_KBoolean);
libevaluation_interop_kref_kotlin_Unit (*createNullableUnit)(void);

/* User functions. */
struct {
struct {
const char* (*evaluate)(const char* rules, const char* user);
} root;
} kotlin;
} libevaluation_interop_ExportedSymbols;
extern libevaluation_interop_ExportedSymbols* libevaluation_interop_symbols(void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* KONAN_LIBEVALUATION_INTEROP_H */
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ifndef KONAN_LIBEVALUATION_INTEROP_H
#define KONAN_LIBEVALUATION_INTEROP_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
typedef bool libevaluation_interop_KBoolean;
#else
typedef _Bool libevaluation_interop_KBoolean;
#endif
typedef unsigned short libevaluation_interop_KChar;
typedef signed char libevaluation_interop_KByte;
typedef short libevaluation_interop_KShort;
typedef int libevaluation_interop_KInt;
typedef long long libevaluation_interop_KLong;
typedef unsigned char libevaluation_interop_KUByte;
typedef unsigned short libevaluation_interop_KUShort;
typedef unsigned int libevaluation_interop_KUInt;
typedef unsigned long long libevaluation_interop_KULong;
typedef float libevaluation_interop_KFloat;
typedef double libevaluation_interop_KDouble;
typedef float __attribute__ ((__vector_size__ (16))) libevaluation_interop_KVector128;
typedef void* libevaluation_interop_KNativePtr;
struct libevaluation_interop_KType;
typedef struct libevaluation_interop_KType libevaluation_interop_KType;

typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Byte;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Short;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Int;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Long;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Float;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Double;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Char;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Boolean;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Unit;


typedef struct {
/* Service functions. */
void (*DisposeStablePointer)(libevaluation_interop_KNativePtr ptr);
void (*DisposeString)(const char* string);
libevaluation_interop_KBoolean (*IsInstance)(libevaluation_interop_KNativePtr ref, const libevaluation_interop_KType* type);
libevaluation_interop_kref_kotlin_Byte (*createNullableByte)(libevaluation_interop_KByte);
libevaluation_interop_kref_kotlin_Short (*createNullableShort)(libevaluation_interop_KShort);
libevaluation_interop_kref_kotlin_Int (*createNullableInt)(libevaluation_interop_KInt);
libevaluation_interop_kref_kotlin_Long (*createNullableLong)(libevaluation_interop_KLong);
libevaluation_interop_kref_kotlin_Float (*createNullableFloat)(libevaluation_interop_KFloat);
libevaluation_interop_kref_kotlin_Double (*createNullableDouble)(libevaluation_interop_KDouble);
libevaluation_interop_kref_kotlin_Char (*createNullableChar)(libevaluation_interop_KChar);
libevaluation_interop_kref_kotlin_Boolean (*createNullableBoolean)(libevaluation_interop_KBoolean);
libevaluation_interop_kref_kotlin_Unit (*createNullableUnit)(void);

/* User functions. */
struct {
struct {
const char* (*evaluate)(const char* rules, const char* user);
} root;
} kotlin;
} libevaluation_interop_ExportedSymbols;
extern libevaluation_interop_ExportedSymbols* libevaluation_interop_symbols(void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* KONAN_LIBEVALUATION_INTEROP_H */
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ifndef KONAN_LIBEVALUATION_INTEROP_H
#define KONAN_LIBEVALUATION_INTEROP_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
typedef bool libevaluation_interop_KBoolean;
#else
typedef _Bool libevaluation_interop_KBoolean;
#endif
typedef unsigned short libevaluation_interop_KChar;
typedef signed char libevaluation_interop_KByte;
typedef short libevaluation_interop_KShort;
typedef int libevaluation_interop_KInt;
typedef long long libevaluation_interop_KLong;
typedef unsigned char libevaluation_interop_KUByte;
typedef unsigned short libevaluation_interop_KUShort;
typedef unsigned int libevaluation_interop_KUInt;
typedef unsigned long long libevaluation_interop_KULong;
typedef float libevaluation_interop_KFloat;
typedef double libevaluation_interop_KDouble;
typedef float __attribute__ ((__vector_size__ (16))) libevaluation_interop_KVector128;
typedef void* libevaluation_interop_KNativePtr;
struct libevaluation_interop_KType;
typedef struct libevaluation_interop_KType libevaluation_interop_KType;

typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Byte;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Short;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Int;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Long;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Float;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Double;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Char;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Boolean;
typedef struct {
libevaluation_interop_KNativePtr pinned;
} libevaluation_interop_kref_kotlin_Unit;


typedef struct {
/* Service functions. */
void (*DisposeStablePointer)(libevaluation_interop_KNativePtr ptr);
void (*DisposeString)(const char* string);
libevaluation_interop_KBoolean (*IsInstance)(libevaluation_interop_KNativePtr ref, const libevaluation_interop_KType* type);
libevaluation_interop_kref_kotlin_Byte (*createNullableByte)(libevaluation_interop_KByte);
libevaluation_interop_kref_kotlin_Short (*createNullableShort)(libevaluation_interop_KShort);
libevaluation_interop_kref_kotlin_Int (*createNullableInt)(libevaluation_interop_KInt);
libevaluation_interop_kref_kotlin_Long (*createNullableLong)(libevaluation_interop_KLong);
libevaluation_interop_kref_kotlin_Float (*createNullableFloat)(libevaluation_interop_KFloat);
libevaluation_interop_kref_kotlin_Double (*createNullableDouble)(libevaluation_interop_KDouble);
libevaluation_interop_kref_kotlin_Char (*createNullableChar)(libevaluation_interop_KChar);
libevaluation_interop_kref_kotlin_Boolean (*createNullableBoolean)(libevaluation_interop_KBoolean);
libevaluation_interop_kref_kotlin_Unit (*createNullableUnit)(void);

/* User functions. */
struct {
struct {
const char* (*evaluate)(const char* rules, const char* user);
} root;
} kotlin;
} libevaluation_interop_ExportedSymbols;
extern libevaluation_interop_ExportedSymbols* libevaluation_interop_symbols(void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* KONAN_LIBEVALUATION_INTEROP_H */
Loading