MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / build_rows

Function build_rows

experiments/human_eval/build_drift_human_eval_packet.py:167–231  ·  view source on GitHub ↗
(
    specs: Sequence[Tuple[str, str, Path]],
    events: Sequence[Dict[str, Any]],
    users: Dict[str, Dict[str, Any]],
    *,
    papers_per_event: int,
    post_days: int,
    seed: int,
    abstract_chars: int,
)

Source from the content-addressed store, hash-verified

165
166
167def build_rows(
168 specs: Sequence[Tuple[str, str, Path]],
169 events: Sequence[Dict[str, Any]],
170 users: Dict[str, Dict[str, Any]],
171 *,
172 papers_per_event: int,
173 post_days: int,
174 seed: int,
175 abstract_chars: int,
176) -> Tuple[List[Dict[str, Any]], List[Dict[str, Any]]]:
177 rng = random.Random(seed)
178 blind_rows: List[Dict[str, Any]] = []
179 key_rows: List[Dict[str, Any]] = []
180 sample_index = 1
181 event_lookup = {(event["user_id"], event["date"]): event for event in events}
182 for method_key, method_name, path in specs:
183 candidates = collect_candidates(path, events, post_days)
184 for event_key, event in event_lookup.items():
185 for paper in choose_event_rows(candidates.get(event_key, []), event, papers_per_event, rng):
186 sample_id = f"HDRIFT_{sample_index:05d}"
187 sample_index += 1
188 user_id = str(event["user_id"])
189 new_topics = {normalize_topic(topic) for topic in event.get("anchor_topics", []) if topic}
190 old_topics = {normalize_topic(topic) for topic in event.get("suppressed_topics", []) if topic}
191 new_hit = topic_match(paper, new_topics)
192 old_hit = topic_match(paper, old_topics)
193 blind_rows.append(
194 {
195 "sample_id": sample_id,
196 "user_profile": common.profile_text(users.get(user_id)),
197 "drift_event_date": event.get("date"),
198 "new_interest_topics": ", ".join(str(topic) for topic in event.get("anchor_topics", []) if topic),
199 "downweighted_old_topics": ", ".join(str(topic) for topic in event.get("suppressed_topics", []) if topic),
200 "recommendation_date": paper.get("date"),
201 "paper_title": common.truncate(paper.get("title"), 500),
202 "paper_abstract": common.truncate(paper.get("abstract"), abstract_chars),
203 "paper_authors": common.truncate(paper.get("authors"), 500),
204 "NewTopicFit": "",
205 "AdaptationAppropriateness": "",
206 "OldNewBalance": "",
207 "DriftDecisionHelpfulness": "",
208 "comments": "",
209 }
210 )
211 key_rows.append(
212 {
213 "sample_id": sample_id,
214 "method_key": method_key,
215 "method_name": method_name,
216 "event_user_id": user_id,
217 "event_date": event.get("date"),
218 "episode_id": paper.get("episode_id"),
219 "recommendation_date": paper.get("date"),
220 "paper_id": paper.get("paper_id"),
221 "system_rank": paper.get("system_rank"),
222 "system_label": paper.get("system_label"),
223 "system_score": paper.get("system_score"),
224 "oracle_label": paper.get("oracle_label"),

Callers 1

mainFunction · 0.70

Calls 5

collect_candidatesFunction · 0.85
choose_event_rowsFunction · 0.85
getMethod · 0.80
normalize_topicFunction · 0.70
topic_matchFunction · 0.70

Tested by

no test coverage detected