Begin rule application
The more I think about this, the more I think it's gonna be super slow and bad. There must bve a good way of doing this, but I'm not sure how...
This commit is contained in:
parent
baf9ef38a4
commit
445ca45fa9
3 changed files with 41 additions and 3 deletions
|
|
@ -14,14 +14,19 @@ const lastfm = @import("../../types.zig").LastFM;
|
||||||
// - logger: Logger attached to the same stream as the Jetzig server.
|
// - logger: Logger attached to the same stream as the Jetzig server.
|
||||||
// - environment: Enum of `{ production, development }`.
|
// - environment: Enum of `{ production, development }`.
|
||||||
pub fn run(allocator: std.mem.Allocator, params: *jetzig.data.Value, env: jetzig.jobs.JobEnv) !void {
|
pub fn run(allocator: std.mem.Allocator, params: *jetzig.data.Value, env: jetzig.jobs.JobEnv) !void {
|
||||||
_ = allocator;
|
|
||||||
//_ = env;
|
//_ = env;
|
||||||
|
const file = try std.fs.cwd().openFile("rules.json", .{ .mode = .read_only });
|
||||||
|
const file_content = try file.readToEndAlloc(allocator, 16_000_000);
|
||||||
|
|
||||||
|
const rules = try std.json.parseFromSliceLeaky(Rules, allocator, file_content, .{});
|
||||||
|
|
||||||
if (params.getT(.array, "scrobbles")) |scrobbles| {
|
if (params.getT(.array, "scrobbles")) |scrobbles| {
|
||||||
for (scrobbles.items()) |item| {
|
for (scrobbles.items()) |item| {
|
||||||
//const fixed_date: u32 = @as(u32, item.getT(.integer, "date").?);
|
//const fixed_date: u32 = @as(u32, item.getT(.integer, "date").?);
|
||||||
const scrobble: Scrobble = .{ .track = item.getT(.string, "track").?, .artist = item.getT(.string, "artist").?, .album = item.getT(.string, "album") orelse "", .date = @as(u64, @bitCast(@as(i64, @truncate(item.getT(.integer, "date").? * 1000)))) };
|
const scrobble: Scrobble = .{ .track = item.getT(.string, "track").?, .artist = item.getT(.string, "artist").?, .album = item.getT(.string, "album") orelse "", .date = @as(u64, @bitCast(@as(i64, @truncate(item.getT(.integer, "date").? * 1000)))) };
|
||||||
|
|
||||||
|
for (rules) |rule| {}
|
||||||
|
|
||||||
// Make hashes
|
// Make hashes
|
||||||
//const album_hash = @as(i32, @bitCast(std.hash.Fnv1a_32.hash(scrobble.album)));
|
//const album_hash = @as(i32, @bitCast(std.hash.Fnv1a_32.hash(scrobble.album)));
|
||||||
//const artist_hash = @as(i32, @bitCast(std.hash.Fnv1a_32.hash(scrobble.artist)));
|
//const artist_hash = @as(i32, @bitCast(std.hash.Fnv1a_32.hash(scrobble.artist)));
|
||||||
|
|
|
||||||
11
src/apply_rule.zig
Normal file
11
src/apply_rule.zig
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
const Scrobble = @import("types").LastFMScrobble;
|
||||||
|
const Rules = @import("types").Rules;
|
||||||
|
|
||||||
|
pub fn applyRule(scrobble: Scrobble, rules: Rules) !Scrobble {
|
||||||
|
var output_scrobble: Scrobble = scrobble;
|
||||||
|
for (rules) |rule| {
|
||||||
|
for (rule.conditionals) |cond| {
|
||||||
|
switch (cond.match_cond) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
const zeit = @import("zeit");
|
|
||||||
|
|
||||||
pub const LastFMScrobble = struct {
|
pub const LastFMScrobble = struct {
|
||||||
track: []const u8,
|
track: []const u8,
|
||||||
artist: []const u8,
|
artist: []const u8,
|
||||||
|
|
@ -36,3 +34,27 @@ pub const SpotifyScrobble = struct {
|
||||||
offline_timestamp: u64,
|
offline_timestamp: u64,
|
||||||
incognito_mode: ?bool,
|
incognito_mode: ?bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Rule = struct {
|
||||||
|
name: []const u8,
|
||||||
|
conditionals: []struct {
|
||||||
|
match_on: MatchOn,
|
||||||
|
match_cond: enum { is, contains },
|
||||||
|
match_txt: []const u8,
|
||||||
|
},
|
||||||
|
actions: []struct {
|
||||||
|
action: []const u8,
|
||||||
|
action_on: enum { is, contains },
|
||||||
|
action_txt: []const u8,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const Rules = struct {
|
||||||
|
rules: []const Rule,
|
||||||
|
};
|
||||||
|
|
||||||
|
const MatchOn = enum {
|
||||||
|
artist,
|
||||||
|
album,
|
||||||
|
song,
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue