#!/usr/bin/env python3
import sys
def read_input(file):
for line in file:
yield line.strip().split(',')
def main():
input = read_input(sys.stdin)
for row in input:
# Ensure the line has the correct number of parts
if len(row) != 6:
continue
user_id, item_id, behaviour_type, user_geohash, item_category, time = row
# Remove the user_geohash field
# Extract hour from the time field (assuming time format is YYYY-MM-DD HH:MM:SS)
hour = time.split(' ')[1].split(':')[0]
# Only consider purchase actions (behaviour_type == 4)
if behaviour_type == '4':
print(f"{hour}\t{item_category}\t1")
if __name__ == "__main__":
main()
#!/usr/bin/env python3
import sys
def read_input(file):
for line in file:
yield line.strip().split('\t')
def main():
current_hour = None
current_category = None
current_count = 0
input = read_input(sys.stdin)
for hour, item_category, count in input:
count = int(count)
if current_hour == hour and current_category == item_category:
current_count += count
else:
if current_hour and current_category:
# Output the results for the current hour and category
print(f"{current_hour}\t{current_category}\t{current_count}")
current_hour = hour
current_category = item_category
current_count = count
# Output the last hour and category's results
if current_hour and current_category:
print(f"{current_hour}\t{current_category}\t{current_count}")
if __name__ == "__main__":
main()