Created
March 4, 2025 18:00
-
-
Save RishiHQ/536c30959aac89d6b81bb94734f132c3 to your computer and use it in GitHub Desktop.
Print my Hinge likes, outbound matches, and outbound match rate based on Hinge's matches.json download
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'time' | |
require 'json' | |
def run_program | |
print_hinge_stats_by_month | |
end | |
def print_hinge_stats_by_month | |
(2019..2025).each do |year| | |
(1..12).each do |month| | |
HingeMonthlyStats.print_stats(month, year) | |
end | |
end | |
end | |
class HingeMonthlyStats | |
def self.print_stats(month, year) | |
return if year >= Time.now.year && month >= Time.now.month | |
interaction_sets = load_interaction_sets | |
stats = HingeMonthlyStats.new(month, year, interaction_sets) | |
message = <<~MSG | |
#{stats.formatted_month_year} | |
Outbound Match Rate: #{stats.outbound_match_rate_formatted}% | |
Outbound Matches: #{stats.outbound_matches} | |
Likes: #{stats.likes} | |
MSG | |
puts message | |
end | |
def self.load_interaction_sets | |
file_path = 'matches.json' | |
json_interaction_sets = JSON.parse(File.read(file_path)) | |
json_interaction_sets.map do |json_interaction_set| | |
HingeInteractionSet.new(json_interaction_set) | |
end | |
end | |
def initialize(month, year, interaction_sets) | |
@month, @year = month, year | |
@interaction_sets = interaction_sets.select do |set| | |
set.contains_like? && set.formatted_like_month == formatted_month_year | |
end | |
end | |
def formatted_month_year | |
DateFormatter.formatted_month_year(@month, @year) | |
end | |
def likes | |
@interaction_sets.count { |set| set.contains_like? } | |
end | |
def outbound_matches | |
@interaction_sets.count { |set| set.is_outbound_match? } | |
end | |
def outbound_match_rate_formatted | |
((outbound_matches / likes.to_f) * 100).round(2) | |
end | |
end | |
# HingeInteractionSet contains the interactions our user had with another user | |
LIKE_INTERACTION = "like".freeze | |
MATCH_INTERACTION = "match".freeze | |
TIMESTAMP = "timestamp".freeze | |
class HingeInteractionSet | |
def initialize(interaction_set) | |
@interaction_set = interaction_set | |
end | |
def contains_like? | |
!@interaction_set[LIKE_INTERACTION].nil? | |
end | |
def is_outbound_match? | |
!@interaction_set[LIKE_INTERACTION].nil? && !@interaction_set[MATCH_INTERACTION].nil? | |
end | |
def formatted_like_month | |
like_time = Time.parse(@interaction_set[LIKE_INTERACTION][0][TIMESTAMP]) | |
DateFormatter.formatted_month_year(like_time.month, like_time.year) | |
end | |
end | |
module DateFormatter | |
def self.formatted_month_year(month, year) | |
Date.new(year, month, 1).strftime("%B %Y").upcase | |
end | |
end | |
run_program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment